home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / dev / gcc / gcc270_src.lha / gcc-2.7.0-amiga / c-typeck.c < prev    next >
C/C++ Source or Header  |  1995-06-15  |  206KB  |  6,563 lines

  1. /* Build expressions with type checking for C compiler.
  2.    Copyright (C) 1987, 88, 91, 92, 93, 94, 1995 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21.  
  22. /* This file is part of the C front end.
  23.    It contains routines to build C expressions given their operands,
  24.    including computing the types of the result, C-specific error checks,
  25.    and some optimization.
  26.  
  27.    There are also routines to build RETURN_STMT nodes and CASE_STMT nodes,
  28.    and to process initializations in declarations (since they work
  29.    like a strange sort of assignment).  */
  30.  
  31. #include "config.h"
  32. #include <stdio.h>
  33. #include "tree.h"
  34. #include "c-tree.h"
  35. #include "flags.h"
  36. #include "output.h"
  37.  
  38. /* Nonzero if we've already printed a "missing braces around initializer"
  39.    message within this initializer.  */
  40. static int missing_braces_mentioned;
  41.  
  42. extern char *index ();
  43. extern char *rindex ();
  44.  
  45. static tree quality_type        PROTO((tree, tree));
  46. static int comp_target_types        PROTO((tree, tree));
  47. static int function_types_compatible_p    PROTO((tree, tree));
  48. static int type_lists_compatible_p    PROTO((tree, tree));
  49. static int self_promoting_type_p    PROTO((tree));
  50. static tree decl_constant_value        PROTO((tree));
  51. static tree lookup_field        PROTO((tree, tree, tree *));
  52. static tree convert_arguments        PROTO((tree, tree, tree, tree));
  53. static tree pointer_int_sum        PROTO((enum tree_code, tree, tree));
  54. static tree pointer_diff        PROTO((tree, tree));
  55. static tree unary_complex_lvalue    PROTO((enum tree_code, tree));
  56. static void pedantic_lvalue_warning    PROTO((enum tree_code));
  57. static tree internal_build_compound_expr PROTO((tree, int));
  58. static tree convert_for_assignment    PROTO((tree, tree, char *, tree,
  59.                            tree, int));
  60. static void warn_for_assignment        PROTO((char *, char *, tree, int));
  61. static tree valid_compound_expr_initializer PROTO((tree, tree));
  62. static void push_string            PROTO((char *));
  63. static void push_member_name        PROTO((tree));
  64. static void push_array_bounds        PROTO((int));
  65. static int spelling_length        PROTO((void));
  66. static char *print_spelling        PROTO((char *));
  67. static char *get_spelling        PROTO((char *));
  68. static void warning_init        PROTO((char *, char *,
  69.                            char *));
  70. static tree digest_init            PROTO((tree, tree, int, int));
  71. static void check_init_type_bitfields    PROTO((tree));
  72. static void output_init_element        PROTO((tree, tree, tree, int));
  73. static void output_pending_init_elements PROTO((int));
  74.  
  75. /* Do `exp = require_complete_type (exp);' to make sure exp
  76.    does not have an incomplete type.  (That includes void types.)  */
  77.  
  78. tree
  79. require_complete_type (value)
  80.      tree value;
  81. {
  82.   tree type = TREE_TYPE (value);
  83.  
  84.   /* First, detect a valid value with a complete type.  */
  85.   if (TYPE_SIZE (type) != 0
  86.       && type != void_type_node)
  87.     return value;
  88.  
  89.   incomplete_type_error (value, type);
  90.   return error_mark_node;
  91. }
  92.  
  93. /* Print an error message for invalid use of an incomplete type.
  94.    VALUE is the expression that was used (or 0 if that isn't known)
  95.    and TYPE is the type that was invalid.  */
  96.  
  97. void
  98. incomplete_type_error (value, type)
  99.      tree value;
  100.      tree type;
  101. {
  102.   char *errmsg;
  103.  
  104.   /* Avoid duplicate error message.  */
  105.   if (TREE_CODE (type) == ERROR_MARK)
  106.     return;
  107.  
  108.   if (value != 0 && (TREE_CODE (value) == VAR_DECL
  109.              || TREE_CODE (value) == PARM_DECL))
  110.     error ("`%s' has an incomplete type",
  111.        IDENTIFIER_POINTER (DECL_NAME (value)));
  112.   else
  113.     {
  114.     retry:
  115.       /* We must print an error message.  Be clever about what it says.  */
  116.  
  117.       switch (TREE_CODE (type))
  118.     {
  119.     case RECORD_TYPE:
  120.       errmsg = "invalid use of undefined type `struct %s'";
  121.       break;
  122.  
  123.     case UNION_TYPE:
  124.       errmsg = "invalid use of undefined type `union %s'";
  125.       break;
  126.  
  127.     case ENUMERAL_TYPE:
  128.       errmsg = "invalid use of undefined type `enum %s'";
  129.       break;
  130.  
  131.     case VOID_TYPE:
  132.       error ("invalid use of void expression");
  133.       return;
  134.  
  135.     case ARRAY_TYPE:
  136.       if (TYPE_DOMAIN (type))
  137.         {
  138.           type = TREE_TYPE (type);
  139.           goto retry;
  140.         }
  141.       error ("invalid use of array with unspecified bounds");
  142.       return;
  143.  
  144.     default:
  145.       abort ();
  146.     }
  147.  
  148.       if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  149.     error (errmsg, IDENTIFIER_POINTER (TYPE_NAME (type)));
  150.       else
  151.     /* If this type has a typedef-name, the TYPE_NAME is a TYPE_DECL.  */
  152.     error ("invalid use of incomplete typedef `%s'",
  153.            IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
  154.     }
  155. }
  156.  
  157. /* Return a variant of TYPE which has all the type qualifiers of LIKE
  158.    as well as those of TYPE.  */
  159.  
  160. static tree
  161. qualify_type (type, like)
  162.      tree type, like;
  163. {
  164.   int constflag = TYPE_READONLY (type) || TYPE_READONLY (like);
  165.   int volflag = TYPE_VOLATILE (type) || TYPE_VOLATILE (like);
  166.   return c_build_type_variant (type, constflag, volflag);
  167. }
  168.  
  169. /* Return the common type of two types.
  170.    We assume that comptypes has already been done and returned 1;
  171.    if that isn't so, this may crash.  In particular, we assume that qualifiers
  172.    match.
  173.  
  174.    This is the type for the result of most arithmetic operations
  175.    if the operands have the given two types.  */
  176.  
  177. tree
  178. common_type (t1, t2)
  179.      tree t1, t2;
  180. {
  181.   register enum tree_code code1;
  182.   register enum tree_code code2;
  183.   tree attributes;
  184.  
  185.   /* Save time if the two types are the same.  */
  186.  
  187.   if (t1 == t2) return t1;
  188.  
  189.   /* If one type is nonsense, use the other.  */
  190.   if (t1 == error_mark_node)
  191.     return t2;
  192.   if (t2 == error_mark_node)
  193.     return t1;
  194.  
  195.   /* Merge the attributes */
  196.  
  197.   { register tree a1, a2;
  198.     a1 = TYPE_ATTRIBUTES (t1);
  199.     a2 = TYPE_ATTRIBUTES (t2);
  200.  
  201.     /* Either one unset?  Take the set one.  */
  202.  
  203.     if (!(attributes = a1))
  204.        attributes = a2;
  205.  
  206.     /* One that completely contains the other?  Take it.  */
  207.  
  208.     else if (a2 && !attribute_list_contained (a1, a2))
  209.        if (attribute_list_contained (a2, a1))
  210.       attributes = a2;
  211.        else
  212.     {
  213.       /* Pick the longest list, and hang on the other list.  */
  214.       /* ??? For the moment we punt on the issue of attrs with args.  */
  215.     
  216.       if (list_length (a1) < list_length (a2))
  217.          attributes = a2, a2 = a1;
  218.  
  219.       for (; a2; a2 = TREE_CHAIN (a2))
  220.         if (lookup_attribute (IDENTIFIER_POINTER (TREE_PURPOSE (a2)),
  221.                   attributes) == NULL_TREE)
  222.           {
  223.         a1 = copy_node (a2);
  224.         TREE_CHAIN (a1) = attributes;
  225.         attributes = a1;
  226.           }
  227.     }
  228.   }
  229.  
  230.   /* Treat an enum type as the unsigned integer type of the same width.  */
  231.  
  232.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  233.     t1 = type_for_size (TYPE_PRECISION (t1), 1);
  234.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  235.     t2 = type_for_size (TYPE_PRECISION (t2), 1);
  236.  
  237.   code1 = TREE_CODE (t1);
  238.   code2 = TREE_CODE (t2);
  239.  
  240.   /* If one type is complex, form the common type of the non-complex
  241.      components, then make that complex.  Use T1 or T2 if it is the
  242.      required type.  */
  243.   if (code1 == COMPLEX_TYPE || code2 == COMPLEX_TYPE)
  244.     {
  245.       tree subtype1 = code1 == COMPLEX_TYPE ? TREE_TYPE (t1) : t1;
  246.       tree subtype2 = code2 == COMPLEX_TYPE ? TREE_TYPE (t2) : t2;
  247.       tree subtype = common_type (subtype1, subtype2);
  248.  
  249.       if (code1 == COMPLEX_TYPE && TREE_TYPE (t1) == subtype)
  250.     return build_type_attribute_variant (t1, attributes);
  251.       else if (code2 == COMPLEX_TYPE && TREE_TYPE (t2) == subtype)
  252.     return build_type_attribute_variant (t2, attributes);
  253.       else
  254.     return build_type_attribute_variant (build_complex_type (subtype),
  255.                          attributes);
  256.     }
  257.  
  258.   switch (code1)
  259.     {
  260.     case INTEGER_TYPE:
  261.     case REAL_TYPE:
  262.       /* If only one is real, use it as the result.  */
  263.  
  264.       if (code1 == REAL_TYPE && code2 != REAL_TYPE)
  265.     return build_type_attribute_variant (t1, attributes);
  266.  
  267.       if (code2 == REAL_TYPE && code1 != REAL_TYPE)
  268.     return build_type_attribute_variant (t2, attributes);
  269.  
  270.       /* Both real or both integers; use the one with greater precision.  */
  271.  
  272.       if (TYPE_PRECISION (t1) > TYPE_PRECISION (t2))
  273.     return build_type_attribute_variant (t1, attributes);
  274.       else if (TYPE_PRECISION (t2) > TYPE_PRECISION (t1))
  275.     return build_type_attribute_variant (t2, attributes);
  276.  
  277.       /* Same precision.  Prefer longs to ints even when same size.  */
  278.  
  279.       if (TYPE_MAIN_VARIANT (t1) == long_unsigned_type_node
  280.       || TYPE_MAIN_VARIANT (t2) == long_unsigned_type_node)
  281.     return build_type_attribute_variant (long_unsigned_type_node,
  282.                          attributes);
  283.  
  284.       if (TYPE_MAIN_VARIANT (t1) == long_integer_type_node
  285.       || TYPE_MAIN_VARIANT (t2) == long_integer_type_node)
  286.     {
  287.       /* But preserve unsignedness from the other type,
  288.          since long cannot hold all the values of an unsigned int.  */
  289.       if (TREE_UNSIGNED (t1) || TREE_UNSIGNED (t2))
  290.          t1 = long_unsigned_type_node;
  291.       else
  292.          t1 = long_integer_type_node;
  293.       return build_type_attribute_variant (t1, attributes);
  294.     }
  295.  
  296.       /* Otherwise prefer the unsigned one.  */
  297.  
  298.       if (TREE_UNSIGNED (t1))
  299.     return build_type_attribute_variant (t1, attributes);
  300.       else
  301.     return build_type_attribute_variant (t2, attributes);
  302.  
  303.     case POINTER_TYPE:
  304.       /* For two pointers, do this recursively on the target type,
  305.      and combine the qualifiers of the two types' targets.  */
  306.       /* This code was turned off; I don't know why.
  307.      But ANSI C specifies doing this with the qualifiers.
  308.      So I turned it on again.  */
  309.       {
  310.     tree target = common_type (TYPE_MAIN_VARIANT (TREE_TYPE (t1)),
  311.                    TYPE_MAIN_VARIANT (TREE_TYPE (t2)));
  312.     int constp
  313.       = TYPE_READONLY (TREE_TYPE (t1)) || TYPE_READONLY (TREE_TYPE (t2));
  314.     int volatilep
  315.       = TYPE_VOLATILE (TREE_TYPE (t1)) || TYPE_VOLATILE (TREE_TYPE (t2));
  316.     t1 = build_pointer_type (c_build_type_variant (target, constp,
  317.                  volatilep));
  318.     return build_type_attribute_variant (t1, attributes);
  319.       }
  320. #if 0
  321.       t1 = build_pointer_type (common_type (TREE_TYPE (t1), TREE_TYPE (t2)));
  322.       return build_type_attribute_variant (t1, attributes);
  323. #endif
  324.  
  325.     case ARRAY_TYPE:
  326.       {
  327.     tree elt = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  328.     /* Save space: see if the result is identical to one of the args.  */
  329.     if (elt == TREE_TYPE (t1) && TYPE_DOMAIN (t1))
  330.       return build_type_attribute_variant (t1, attributes);
  331.     if (elt == TREE_TYPE (t2) && TYPE_DOMAIN (t2))
  332.       return build_type_attribute_variant (t2, attributes);
  333.     /* Merge the element types, and have a size if either arg has one.  */
  334.     t1 = build_array_type (elt, TYPE_DOMAIN (TYPE_DOMAIN (t1) ? t1 : t2));
  335.     return build_type_attribute_variant (t1, attributes);
  336.       }
  337.  
  338.     case FUNCTION_TYPE:
  339.       /* Function types: prefer the one that specified arg types.
  340.      If both do, merge the arg types.  Also merge the return types.  */
  341.       {
  342.     tree valtype = common_type (TREE_TYPE (t1), TREE_TYPE (t2));
  343.     tree p1 = TYPE_ARG_TYPES (t1);
  344.     tree p2 = TYPE_ARG_TYPES (t2);
  345.     int len;
  346.     tree newargs, n;
  347.     int i;
  348.  
  349.     /* Save space: see if the result is identical to one of the args.  */
  350.     if (valtype == TREE_TYPE (t1) && ! TYPE_ARG_TYPES (t2))
  351.       return build_type_attribute_variant (t1, attributes);
  352.     if (valtype == TREE_TYPE (t2) && ! TYPE_ARG_TYPES (t1))
  353.       return build_type_attribute_variant (t2, attributes);
  354.  
  355.     /* Simple way if one arg fails to specify argument types.  */
  356.     if (TYPE_ARG_TYPES (t1) == 0)
  357.      {
  358.        t1 = build_function_type (valtype, TYPE_ARG_TYPES (t2));
  359.        return build_type_attribute_variant (t1, attributes);
  360.      }
  361.     if (TYPE_ARG_TYPES (t2) == 0)
  362.      {
  363.        t1 = build_function_type (valtype, TYPE_ARG_TYPES (t1));
  364.        return build_type_attribute_variant (t1, attributes);
  365.      }
  366.  
  367.     /* If both args specify argument types, we must merge the two
  368.        lists, argument by argument.  */
  369.  
  370.     len = list_length (p1);
  371.     newargs = 0;
  372.  
  373.     for (i = 0; i < len; i++)
  374.       newargs = tree_cons (NULL_TREE, NULL_TREE, newargs);
  375.  
  376.     n = newargs;
  377.  
  378.     for (; p1;
  379.          p1 = TREE_CHAIN (p1), p2 = TREE_CHAIN (p2), n = TREE_CHAIN (n))
  380.       {
  381.         /* A null type means arg type is not specified.
  382.            Take whatever the other function type has.  */
  383.         if (TREE_VALUE (p1) == 0)
  384.           {
  385.         TREE_VALUE (n) = TREE_VALUE (p2);
  386.         goto parm_done;
  387.           }
  388.         if (TREE_VALUE (p2) == 0)
  389.           {
  390.         TREE_VALUE (n) = TREE_VALUE (p1);
  391.         goto parm_done;
  392.           }
  393.           
  394.         /* Given  wait (union {union wait *u; int *i} *)
  395.            and  wait (union wait *),
  396.            prefer  union wait *  as type of parm.  */
  397.         if (TREE_CODE (TREE_VALUE (p1)) == UNION_TYPE
  398.         && TREE_VALUE (p1) != TREE_VALUE (p2))
  399.           {
  400.         tree memb;
  401.         for (memb = TYPE_FIELDS (TREE_VALUE (p1));
  402.              memb; memb = TREE_CHAIN (memb))
  403.           if (comptypes (TREE_TYPE (memb), TREE_VALUE (p2)))
  404.             {
  405.               TREE_VALUE (n) = TREE_VALUE (p2);
  406.               if (pedantic)
  407.             pedwarn ("function types not truly compatible in ANSI C");
  408.               goto parm_done;
  409.             }
  410.           }
  411.         if (TREE_CODE (TREE_VALUE (p2)) == UNION_TYPE
  412.         && TREE_VALUE (p2) != TREE_VALUE (p1))
  413.           {
  414.         tree memb;
  415.         for (memb = TYPE_FIELDS (TREE_VALUE (p2));
  416.              memb; memb = TREE_CHAIN (memb))
  417.           if (comptypes (TREE_TYPE (memb), TREE_VALUE (p1)))
  418.             {
  419.               TREE_VALUE (n) = TREE_VALUE (p1);
  420.               if (pedantic)
  421.             pedwarn ("function types not truly compatible in ANSI C");
  422.               goto parm_done;
  423.             }
  424.           }
  425.         TREE_VALUE (n) = common_type (TREE_VALUE (p1), TREE_VALUE (p2));
  426.       parm_done: ;
  427.       }
  428.  
  429.     t1 = build_function_type (valtype, newargs);
  430.     /* ... falls through ... */
  431.       }
  432.  
  433.     default:
  434.       return build_type_attribute_variant (t1, attributes);
  435.     }
  436.  
  437. }
  438.  
  439. /* Return 1 if TYPE1 and TYPE2 are compatible types for assignment
  440.    or various other operations.  Return 2 if they are compatible
  441.    but a warning may be needed if you use them together.  */
  442.  
  443. int
  444. comptypes (type1, type2)
  445.      tree type1, type2;
  446. {
  447.   register tree t1 = type1;
  448.   register tree t2 = type2;
  449.   int attrval, val;
  450.  
  451.   /* Suppress errors caused by previously reported errors.  */
  452.  
  453.   if (t1 == t2 || TREE_CODE (t1) == ERROR_MARK || TREE_CODE (t2) == ERROR_MARK)
  454.     return 1;
  455.  
  456.   /* Treat an enum type as the integer type of the same width and 
  457.      signedness.  */
  458.  
  459.   if (TREE_CODE (t1) == ENUMERAL_TYPE)
  460.     t1 = type_for_size (TYPE_PRECISION (t1), TREE_UNSIGNED (t1));
  461.   if (TREE_CODE (t2) == ENUMERAL_TYPE)
  462.     t2 = type_for_size (TYPE_PRECISION (t2), TREE_UNSIGNED (t2));
  463.  
  464.   if (t1 == t2)
  465.     return 1;
  466.  
  467.   /* Different classes of types can't be compatible.  */
  468.  
  469.   if (TREE_CODE (t1) != TREE_CODE (t2)) return 0;
  470.  
  471.   /* Qualifiers must match.  */
  472.  
  473.   if (TYPE_READONLY (t1) != TYPE_READONLY (t2))
  474.     return 0;
  475.   if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
  476.     return 0;
  477.  
  478.   /* Allow for two different type nodes which have essentially the same
  479.      definition.  Note that we already checked for equality of the type
  480.      type qualifiers (just above).  */
  481.  
  482.   if (TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2))
  483.     return 1;
  484.  
  485. #ifndef COMP_TYPE_ATTRIBUTES
  486. #define COMP_TYPE_ATTRIBUTES(t1,t2)    1
  487. #endif
  488.  
  489.   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
  490.   if (! (attrval = COMP_TYPE_ATTRIBUTES (t1, t2)))
  491.      return 0;
  492.  
  493.   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
  494.   val = 0;
  495.  
  496.   switch (TREE_CODE (t1))
  497.     {
  498.     case POINTER_TYPE:
  499.       val = (TREE_TYPE (t1) == TREE_TYPE (t2)
  500.           ? 1 : comptypes (TREE_TYPE (t1), TREE_TYPE (t2)));
  501.       break;
  502.  
  503.     case FUNCTION_TYPE:
  504.       val = function_types_compatible_p (t1, t2);
  505.       break;
  506.  
  507.     case ARRAY_TYPE:
  508.       {
  509.     tree d1 = TYPE_DOMAIN (t1);
  510.     tree d2 = TYPE_DOMAIN (t2);
  511.     val = 1;
  512.  
  513.     /* Target types must match incl. qualifiers.  */
  514.     if (TREE_TYPE (t1) != TREE_TYPE (t2)
  515.         && 0 == (val = comptypes (TREE_TYPE (t1), TREE_TYPE (t2))))
  516.       return 0;
  517.  
  518.     /* Sizes must match unless one is missing or variable.  */
  519.     if (d1 == 0 || d2 == 0 || d1 == d2
  520.         || TREE_CODE (TYPE_MIN_VALUE (d1)) != INTEGER_CST
  521.         || TREE_CODE (TYPE_MIN_VALUE (d2)) != INTEGER_CST
  522.         || TREE_CODE (TYPE_MAX_VALUE (d1)) != INTEGER_CST
  523.         || TREE_CODE (TYPE_MAX_VALUE (d2)) != INTEGER_CST)
  524.       break;
  525.  
  526.     if (! ((TREE_INT_CST_LOW (TYPE_MIN_VALUE (d1))
  527.           == TREE_INT_CST_LOW (TYPE_MIN_VALUE (d2)))
  528.          && (TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d1))
  529.              == TREE_INT_CST_HIGH (TYPE_MIN_VALUE (d2)))
  530.          && (TREE_INT_CST_LOW (TYPE_MAX_VALUE (d1))
  531.              == TREE_INT_CST_LOW (TYPE_MAX_VALUE (d2)))
  532.          && (TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d1))
  533.              == TREE_INT_CST_HIGH (TYPE_MAX_VALUE (d2)))))
  534.        val = 0;
  535.         break;
  536.       }
  537.  
  538.     case RECORD_TYPE:
  539.       if (maybe_objc_comptypes (t1, t2, 0) == 1)
  540.     val = 1;
  541.       break;
  542.     }
  543.   return attrval == 2 && val == 1 ? 2 : val;
  544. }
  545.  
  546. /* Return 1 if TTL and TTR are pointers to types that are equivalent,
  547.    ignoring their qualifiers.  */
  548.  
  549. static int
  550. comp_target_types (ttl, ttr)
  551.      tree ttl, ttr;
  552. {
  553.   int val;
  554.  
  555.   /* Give maybe_objc_comptypes a crack at letting these types through.  */
  556.   if (val = maybe_objc_comptypes (ttl, ttr, 1) >= 0)
  557.     return val;
  558.  
  559.   val = comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (ttl)),
  560.            TYPE_MAIN_VARIANT (TREE_TYPE (ttr)));
  561.  
  562.   if (val == 2 && pedantic)
  563.     pedwarn ("types are not quite compatible");
  564.   return val;
  565. }
  566.  
  567. /* Subroutines of `comptypes'.  */
  568.  
  569. /* Return 1 if two function types F1 and F2 are compatible.
  570.    If either type specifies no argument types,
  571.    the other must specify a fixed number of self-promoting arg types.
  572.    Otherwise, if one type specifies only the number of arguments, 
  573.    the other must specify that number of self-promoting arg types.
  574.    Otherwise, the argument types must match.  */
  575.  
  576. static int
  577. function_types_compatible_p (f1, f2)
  578.      tree f1, f2;
  579. {
  580.   tree args1, args2;
  581.   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
  582.   int val = 1;
  583.   int val1;
  584.  
  585.   if (!(TREE_TYPE (f1) == TREE_TYPE (f2)
  586.     || (val = comptypes (TREE_TYPE (f1), TREE_TYPE (f2)))))
  587.     return 0;
  588.  
  589.   args1 = TYPE_ARG_TYPES (f1);
  590.   args2 = TYPE_ARG_TYPES (f2);
  591.  
  592.   /* An unspecified parmlist matches any specified parmlist
  593.      whose argument types don't need default promotions.  */
  594.  
  595.   if (args1 == 0)
  596.     {
  597.       if (!self_promoting_args_p (args2))
  598.     return 0;
  599.       /* If one of these types comes from a non-prototype fn definition,
  600.      compare that with the other type's arglist.
  601.      If they don't match, ask for a warning (but no error).  */
  602.       if (TYPE_ACTUAL_ARG_TYPES (f1)
  603.       && 1 != type_lists_compatible_p (args2, TYPE_ACTUAL_ARG_TYPES (f1)))
  604.     val = 2;
  605.       return val;
  606.     }
  607.   if (args2 == 0)
  608.     {
  609.       if (!self_promoting_args_p (args1))
  610.     return 0;
  611.       if (TYPE_ACTUAL_ARG_TYPES (f2)
  612.       && 1 != type_lists_compatible_p (args1, TYPE_ACTUAL_ARG_TYPES (f2)))
  613.     val = 2;
  614.       return val;
  615.     }
  616.  
  617.   /* Both types have argument lists: compare them and propagate results.  */
  618.   val1 = type_lists_compatible_p (args1, args2);
  619.   return val1 != 1 ? val1 : val;
  620. }
  621.  
  622. /* Check two lists of types for compatibility,
  623.    returning 0 for incompatible, 1 for compatible,
  624.    or 2 for compatible with warning.  */
  625.  
  626. static int
  627. type_lists_compatible_p (args1, args2)
  628.      tree args1, args2;
  629. {
  630.   /* 1 if no need for warning yet, 2 if warning cause has been seen.  */
  631.   int val = 1;
  632.   int newval = 0;
  633.  
  634.   while (1)
  635.     {
  636.       if (args1 == 0 && args2 == 0)
  637.     return val;
  638.       /* If one list is shorter than the other,
  639.      they fail to match.  */
  640.       if (args1 == 0 || args2 == 0)
  641.     return 0;
  642.       /* A null pointer instead of a type
  643.      means there is supposed to be an argument
  644.      but nothing is specified about what type it has.
  645.      So match anything that self-promotes.  */
  646.       if (TREE_VALUE (args1) == 0)
  647.     {
  648.       if (! self_promoting_type_p (TREE_VALUE (args2)))
  649.         return 0;
  650.     }
  651.       else if (TREE_VALUE (args2) == 0)
  652.     {
  653.       if (! self_promoting_type_p (TREE_VALUE (args1)))
  654.         return 0;
  655.     }
  656.       else if (! (newval = comptypes (TREE_VALUE (args1), TREE_VALUE (args2))))
  657.     {
  658.       /* Allow  wait (union {union wait *u; int *i} *)
  659.          and  wait (union wait *)  to be compatible.  */
  660.       if (TREE_CODE (TREE_VALUE (args1)) == UNION_TYPE
  661.           && (TYPE_NAME (TREE_VALUE (args1)) == 0
  662.           || TYPE_TRANSPARENT_UNION (TREE_VALUE (args1)))
  663.           && TREE_CODE (TYPE_SIZE (TREE_VALUE (args1))) == INTEGER_CST
  664.           && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args1)),
  665.                      TYPE_SIZE (TREE_VALUE (args2))))
  666.         {
  667.           tree memb;
  668.           for (memb = TYPE_FIELDS (TREE_VALUE (args1));
  669.            memb; memb = TREE_CHAIN (memb))
  670.         if (comptypes (TREE_TYPE (memb), TREE_VALUE (args2)))
  671.           break;
  672.           if (memb == 0)
  673.         return 0;
  674.         }
  675.       else if (TREE_CODE (TREE_VALUE (args2)) == UNION_TYPE
  676.            && (TYPE_NAME (TREE_VALUE (args2)) == 0
  677.                || TYPE_TRANSPARENT_UNION (TREE_VALUE (args2)))
  678.            && TREE_CODE (TYPE_SIZE (TREE_VALUE (args2))) == INTEGER_CST
  679.            && tree_int_cst_equal (TYPE_SIZE (TREE_VALUE (args2)),
  680.                       TYPE_SIZE (TREE_VALUE (args1))))
  681.         {
  682.           tree memb;
  683.           for (memb = TYPE_FIELDS (TREE_VALUE (args2));
  684.            memb; memb = TREE_CHAIN (memb))
  685.         if (comptypes (TREE_TYPE (memb), TREE_VALUE (args1)))
  686.           break;
  687.           if (memb == 0)
  688.         return 0;
  689.         }
  690.       else
  691.         return 0;
  692.     }
  693.  
  694.       /* comptypes said ok, but record if it said to warn.  */
  695.       if (newval > val)
  696.     val = newval;
  697.  
  698.       args1 = TREE_CHAIN (args1);
  699.       args2 = TREE_CHAIN (args2);
  700.     }
  701. }
  702.  
  703. /* Return 1 if PARMS specifies a fixed number of parameters
  704.    and none of their types is affected by default promotions.  */
  705.  
  706. int
  707. self_promoting_args_p (parms)
  708.      tree parms;
  709. {
  710.   register tree t;
  711.   for (t = parms; t; t = TREE_CHAIN (t))
  712.     {
  713.       register tree type = TREE_VALUE (t);
  714.  
  715.       if (TREE_CHAIN (t) == 0 && type != void_type_node)
  716.     return 0;
  717.  
  718.       if (type == 0)
  719.     return 0;
  720.  
  721.       if (TYPE_MAIN_VARIANT (type) == float_type_node)
  722.     return 0;
  723.  
  724.       if (C_PROMOTING_INTEGER_TYPE_P (type))
  725.     return 0;
  726.     }
  727.   return 1;
  728. }
  729.  
  730. /* Return 1 if TYPE is not affected by default promotions.  */
  731.  
  732. static int
  733. self_promoting_type_p (type)
  734.      tree type;
  735. {
  736.   if (TYPE_MAIN_VARIANT (type) == float_type_node)
  737.     return 0;
  738.  
  739.   if (C_PROMOTING_INTEGER_TYPE_P (type))
  740.     return 0;
  741.  
  742.   return 1;
  743. }
  744.  
  745. /* Return an unsigned type the same as TYPE in other respects.  */
  746.  
  747. tree
  748. unsigned_type (type)
  749.      tree type;
  750. {
  751.   tree type1 = TYPE_MAIN_VARIANT (type);
  752.   if (type1 == signed_char_type_node || type1 == char_type_node)
  753.     return unsigned_char_type_node;
  754.   if (type1 == integer_type_node)
  755.     return unsigned_type_node;
  756.   if (type1 == short_integer_type_node)
  757.     return short_unsigned_type_node;
  758.   if (type1 == long_integer_type_node)
  759.     return long_unsigned_type_node;
  760.   if (type1 == long_long_integer_type_node)
  761.     return long_long_unsigned_type_node;
  762.   return type;
  763. }
  764.  
  765. /* Return a signed type the same as TYPE in other respects.  */
  766.  
  767. tree
  768. signed_type (type)
  769.      tree type;
  770. {
  771.   tree type1 = TYPE_MAIN_VARIANT (type);
  772.   if (type1 == unsigned_char_type_node || type1 == char_type_node)
  773.     return signed_char_type_node;
  774.   if (type1 == unsigned_type_node)
  775.     return integer_type_node;
  776.   if (type1 == short_unsigned_type_node)
  777.     return short_integer_type_node;
  778.   if (type1 == long_unsigned_type_node)
  779.     return long_integer_type_node;
  780.   if (type1 == long_long_unsigned_type_node)
  781.     return long_long_integer_type_node;
  782.   return type;
  783. }
  784.  
  785. /* Return a type the same as TYPE except unsigned or
  786.    signed according to UNSIGNEDP.  */
  787.  
  788. tree
  789. signed_or_unsigned_type (unsignedp, type)
  790.      int unsignedp;
  791.      tree type;
  792. {
  793.   if (! INTEGRAL_TYPE_P (type))
  794.     return type;
  795.   if (TYPE_PRECISION (type) == TYPE_PRECISION (signed_char_type_node))
  796.     return unsignedp ? unsigned_char_type_node : signed_char_type_node;
  797.   if (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 
  798.     return unsignedp ? unsigned_type_node : integer_type_node;
  799.   if (TYPE_PRECISION (type) == TYPE_PRECISION (short_integer_type_node)) 
  800.     return unsignedp ? short_unsigned_type_node : short_integer_type_node;
  801.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_integer_type_node)) 
  802.     return unsignedp ? long_unsigned_type_node : long_integer_type_node;
  803.   if (TYPE_PRECISION (type) == TYPE_PRECISION (long_long_integer_type_node)) 
  804.     return (unsignedp ? long_long_unsigned_type_node
  805.         : long_long_integer_type_node);
  806.   return type;
  807. }
  808.  
  809. /* Compute the value of the `sizeof' operator.  */
  810.  
  811. tree
  812. c_sizeof (type)
  813.      tree type;
  814. {
  815.   enum tree_code code = TREE_CODE (type);
  816.   tree t;
  817.  
  818.   if (code == FUNCTION_TYPE)
  819.     {
  820.       if (pedantic || warn_pointer_arith)
  821.     pedwarn ("sizeof applied to a function type");
  822.       return size_int (1);
  823.     }
  824.   if (code == VOID_TYPE)
  825.     {
  826.       if (pedantic || warn_pointer_arith)
  827.     pedwarn ("sizeof applied to a void type");
  828.       return size_int (1);
  829.     }
  830.   if (code == ERROR_MARK)
  831.     return size_int (1);
  832.   if (TYPE_SIZE (type) == 0)
  833.     {
  834.       error ("sizeof applied to an incomplete type");
  835.       return size_int (0);
  836.     }
  837.  
  838.   /* Convert in case a char is more than one unit.  */
  839.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  840.           size_int (TYPE_PRECISION (char_type_node)));
  841.   /* size_binop does not put the constant in range, so do it now.  */
  842.   if (TREE_CODE (t) == INTEGER_CST && force_fit_type (t, 0))
  843.     TREE_CONSTANT_OVERFLOW (t) = TREE_OVERFLOW (t) = 1;
  844.   return t;
  845. }
  846.  
  847. tree
  848. c_sizeof_nowarn (type)
  849.      tree type;
  850. {
  851.   enum tree_code code = TREE_CODE (type);
  852.   tree t;
  853.  
  854.   if (code == FUNCTION_TYPE
  855.       || code == VOID_TYPE
  856.       || code == ERROR_MARK)
  857.     return size_int (1);
  858.   if (TYPE_SIZE (type) == 0)
  859.     return size_int (0);
  860.  
  861.   /* Convert in case a char is more than one unit.  */
  862.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  863.           size_int (TYPE_PRECISION (char_type_node)));
  864.   force_fit_type (t, 0);
  865.   return t;
  866. }
  867.  
  868. /* Compute the size to increment a pointer by.  */
  869.  
  870. tree
  871. c_size_in_bytes (type)
  872.      tree type;
  873. {
  874.   enum tree_code code = TREE_CODE (type);
  875.   tree t;
  876.  
  877.   if (code == FUNCTION_TYPE)
  878.     return size_int (1);
  879.   if (code == VOID_TYPE)
  880.     return size_int (1);
  881.   if (code == ERROR_MARK)
  882.     return size_int (1);
  883.   if (TYPE_SIZE (type) == 0)
  884.     {
  885.       error ("arithmetic on pointer to an incomplete type");
  886.       return size_int (1);
  887.     }
  888.  
  889.   /* Convert in case a char is more than one unit.  */
  890.   t = size_binop (CEIL_DIV_EXPR, TYPE_SIZE (type), 
  891.              size_int (BITS_PER_UNIT));
  892.   force_fit_type (t, 0);
  893.   return t;
  894. }
  895.  
  896. /* Implement the __alignof keyword: Return the minimum required
  897.    alignment of TYPE, measured in bytes.  */
  898.  
  899. tree
  900. c_alignof (type)
  901.      tree type;
  902. {
  903.   enum tree_code code = TREE_CODE (type);
  904.  
  905.   if (code == FUNCTION_TYPE)
  906.     return size_int (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  907.  
  908.   if (code == VOID_TYPE || code == ERROR_MARK)
  909.     return size_int (1);
  910.  
  911.   return size_int (TYPE_ALIGN (type) / BITS_PER_UNIT);
  912. }
  913.  
  914. /* Implement the __alignof keyword: Return the minimum required
  915.    alignment of EXPR, measured in bytes.  For VAR_DECL's and
  916.    FIELD_DECL's return DECL_ALIGN (which can be set from an
  917.    "aligned" __attribute__ specification).  */
  918.  
  919. tree
  920. c_alignof_expr (expr)
  921.      tree expr;
  922. {
  923.   if (TREE_CODE (expr) == VAR_DECL)
  924.     return size_int (DECL_ALIGN (expr) / BITS_PER_UNIT);
  925.  
  926.   if (TREE_CODE (expr) == COMPONENT_REF
  927.       && DECL_BIT_FIELD (TREE_OPERAND (expr, 1)))
  928.     {
  929.       error ("`__alignof' applied to a bit-field");
  930.       return size_int (1);
  931.     }
  932.   else if (TREE_CODE (expr) == COMPONENT_REF
  933.       && TREE_CODE (TREE_OPERAND (expr, 1)) == FIELD_DECL)
  934.     return size_int (DECL_ALIGN (TREE_OPERAND (expr, 1)) / BITS_PER_UNIT);
  935.  
  936.   if (TREE_CODE (expr) == INDIRECT_REF)
  937.     {
  938.       tree t = TREE_OPERAND (expr, 0);
  939.       tree best = t;
  940.       int bestalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  941.  
  942.       while (TREE_CODE (t) == NOP_EXPR
  943.           && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == POINTER_TYPE)
  944.     {
  945.       int thisalign;
  946.  
  947.       t = TREE_OPERAND (t, 0);
  948.       thisalign = TYPE_ALIGN (TREE_TYPE (TREE_TYPE (t)));
  949.       if (thisalign > bestalign)
  950.         best = t, bestalign = thisalign;
  951.     }
  952.       return c_alignof (TREE_TYPE (TREE_TYPE (best)));
  953.     }
  954.   else
  955.     return c_alignof (TREE_TYPE (expr));
  956. }
  957. /* Return either DECL or its known constant value (if it has one).  */
  958.  
  959. static tree
  960. decl_constant_value (decl)
  961.      tree decl;
  962. {
  963.   if (! TREE_PUBLIC (decl)
  964.       /* Don't change a variable array bound or initial value to a constant
  965.      in a place where a variable is invalid.  */
  966.       && current_function_decl != 0
  967.       && ! pedantic
  968.       && ! TREE_THIS_VOLATILE (decl)
  969.       && TREE_READONLY (decl) && ! ITERATOR_P (decl)
  970.       && DECL_INITIAL (decl) != 0
  971.       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
  972.       /* This is invalid if initial value is not constant.
  973.      If it has either a function call, a memory reference,
  974.      or a variable, then re-evaluating it could give different results.  */
  975.       && TREE_CONSTANT (DECL_INITIAL (decl))
  976.       /* Check for cases where this is sub-optimal, even though valid.  */
  977.       && TREE_CODE (DECL_INITIAL (decl)) != CONSTRUCTOR
  978.       && DECL_MODE (decl) != BLKmode)
  979.     return DECL_INITIAL (decl);
  980.   return decl;
  981. }
  982.  
  983. /* Perform default promotions for C data used in expressions.
  984.    Arrays and functions are converted to pointers;
  985.    enumeral types or short or char, to int.
  986.    In addition, manifest constants symbols are replaced by their values.  */
  987.  
  988. tree
  989. default_conversion (exp)
  990.      tree exp;
  991. {
  992.   register tree type = TREE_TYPE (exp);
  993.   register enum tree_code code = TREE_CODE (type);
  994.  
  995.   /* Constants can be used directly unless they're not loadable.  */
  996.   if (TREE_CODE (exp) == CONST_DECL)
  997.     exp = DECL_INITIAL (exp);
  998.  
  999.   /* Replace a nonvolatile const static variable with its value unless
  1000.      it is an array, in which case we must be sure that taking the
  1001.      address of the array produces consistent results.  */
  1002.   else if (optimize && TREE_CODE (exp) == VAR_DECL && code != ARRAY_TYPE)
  1003.     {
  1004.       exp = decl_constant_value (exp);
  1005.       type = TREE_TYPE (exp);
  1006.     }
  1007.  
  1008.   /* Strip NON_LVALUE_EXPRs and no-op conversions, since we aren't using as
  1009.      an lvalue.  */
  1010.   /* Do not use STRIP_NOPS here!  It will remove conversions from pointer
  1011.      to integer and cause infinite recursion.  */
  1012.   while (TREE_CODE (exp) == NON_LVALUE_EXPR
  1013.      || (TREE_CODE (exp) == NOP_EXPR
  1014.          && TREE_TYPE (TREE_OPERAND (exp, 0)) == TREE_TYPE (exp)))
  1015.     exp = TREE_OPERAND (exp, 0);
  1016.  
  1017.   /* Normally convert enums to int,
  1018.      but convert wide enums to something wider.  */
  1019.   if (code == ENUMERAL_TYPE)
  1020.     {
  1021.       type = type_for_size (MAX (TYPE_PRECISION (type),
  1022.                  TYPE_PRECISION (integer_type_node)),
  1023.                 ((flag_traditional
  1024.                   || TYPE_PRECISION (type) >= TYPE_PRECISION (integer_type_node))
  1025.                  && TREE_UNSIGNED (type)));
  1026.       return convert (type, exp);
  1027.     }
  1028.  
  1029.   if (C_PROMOTING_INTEGER_TYPE_P (type))
  1030.     {
  1031.       /* Traditionally, unsignedness is preserved in default promotions.
  1032.          Also preserve unsignedness if not really getting any wider.  */
  1033.       if (TREE_UNSIGNED (type)
  1034.       && (flag_traditional
  1035.           || TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
  1036.     return convert (unsigned_type_node, exp);
  1037.       return convert (integer_type_node, exp);
  1038.     }
  1039.   if (flag_traditional && !flag_allow_single_precision
  1040.       && TYPE_MAIN_VARIANT (type) == float_type_node)
  1041.     return convert (double_type_node, exp);
  1042.   if (code == VOID_TYPE)
  1043.     {
  1044.       error ("void value not ignored as it ought to be");
  1045.       return error_mark_node;
  1046.     }
  1047.   if (code == FUNCTION_TYPE)
  1048.     {
  1049.       return build_unary_op (ADDR_EXPR, exp, 0);
  1050.     }
  1051.   if (code == ARRAY_TYPE)
  1052.     {
  1053.       register tree adr;
  1054.       tree restype = TREE_TYPE (type);
  1055.       tree ptrtype;
  1056.       int constp = 0;
  1057.       int volatilep = 0;
  1058.  
  1059.       if (TREE_CODE_CLASS (TREE_CODE (exp)) == 'r'
  1060.       || TREE_CODE_CLASS (TREE_CODE (exp)) == 'd')
  1061.     {
  1062.       constp = TREE_READONLY (exp);
  1063.       volatilep = TREE_THIS_VOLATILE (exp);
  1064.     }
  1065.  
  1066.       if (TYPE_READONLY (type) || TYPE_VOLATILE (type)
  1067.       || constp || volatilep)
  1068.     restype = c_build_type_variant (restype,
  1069.                     TYPE_READONLY (type) || constp,
  1070.                     TYPE_VOLATILE (type) || volatilep);
  1071.  
  1072.       if (TREE_CODE (exp) == INDIRECT_REF)
  1073.     return convert (TYPE_POINTER_TO (restype),
  1074.             TREE_OPERAND (exp, 0));
  1075.  
  1076.       if (TREE_CODE (exp) == COMPOUND_EXPR)
  1077.     {
  1078.       tree op1 = default_conversion (TREE_OPERAND (exp, 1));
  1079.       return build (COMPOUND_EXPR, TREE_TYPE (op1),
  1080.             TREE_OPERAND (exp, 0), op1);
  1081.     }
  1082.  
  1083.       if (!lvalue_p (exp)
  1084.       && ! (TREE_CODE (exp) == CONSTRUCTOR && TREE_STATIC (exp)))
  1085.     {
  1086.       error ("invalid use of non-lvalue array");
  1087.       return error_mark_node;
  1088.     }
  1089.  
  1090.       ptrtype = build_pointer_type (restype);
  1091.  
  1092.       if (TREE_CODE (exp) == VAR_DECL)
  1093.     {
  1094.       /* ??? This is not really quite correct
  1095.          in that the type of the operand of ADDR_EXPR
  1096.          is not the target type of the type of the ADDR_EXPR itself.
  1097.          Question is, can this lossage be avoided?  */
  1098.       adr = build1 (ADDR_EXPR, ptrtype, exp);
  1099.       if (mark_addressable (exp) == 0)
  1100.         return error_mark_node;
  1101.       TREE_CONSTANT (adr) = staticp (exp);
  1102.       TREE_SIDE_EFFECTS (adr) = 0;   /* Default would be, same as EXP.  */
  1103.       return adr;
  1104.     }
  1105.       /* This way is better for a COMPONENT_REF since it can
  1106.      simplify the offset for a component.  */
  1107.       adr = build_unary_op (ADDR_EXPR, exp, 1);
  1108.       return convert (ptrtype, adr);
  1109.     }
  1110.   return exp;
  1111. }
  1112.  
  1113. /* Look up component name in the structure type definition.
  1114.  
  1115.    If this component name is found indirectly within an anonymous union,
  1116.    store in *INDIRECT the component which directly contains
  1117.    that anonymous union.  Otherwise, set *INDIRECT to 0.  */
  1118.      
  1119. static tree
  1120. lookup_field (type, component, indirect)
  1121.      tree type, component;
  1122.      tree *indirect;
  1123. {
  1124.   tree field;
  1125.  
  1126.   /* If TYPE_LANG_SPECIFIC is set, then it is a sorted array of pointers
  1127.      to the field elements.  Use a binary search on this array to quickly
  1128.      find the element.  Otherwise, do a linear search.  TYPE_LANG_SPECIFIC
  1129.      will always be set for structures which have many elements.  */
  1130.  
  1131.   if (TYPE_LANG_SPECIFIC (type))
  1132.     {
  1133.       int bot, top, half;
  1134.       tree *field_array = &TYPE_LANG_SPECIFIC (type)->elts[0];
  1135.  
  1136.       field = TYPE_FIELDS (type);
  1137.       bot = 0;
  1138.       top = TYPE_LANG_SPECIFIC (type)->len;
  1139.       while (top - bot > 1)
  1140.     {
  1141.       HOST_WIDE_INT cmp;
  1142.  
  1143.       half = (top - bot + 1) >> 1;
  1144.       field = field_array[bot+half];
  1145.  
  1146.       if (DECL_NAME (field) == NULL_TREE)
  1147.         {
  1148.           /* Step through all anon unions in linear fashion.  */
  1149.           while (DECL_NAME (field_array[bot]) == NULL_TREE)
  1150.         {
  1151.           tree anon, junk;
  1152.  
  1153.           field = field_array[bot++];
  1154.           anon = lookup_field (TREE_TYPE (field), component, &junk);
  1155.           if (anon != NULL_TREE)
  1156.             {
  1157.               *indirect = field;
  1158.               return anon;
  1159.             }
  1160.         }
  1161.  
  1162.           /* Entire record is only anon unions.  */
  1163.           if (bot > top)
  1164.         return NULL_TREE;
  1165.  
  1166.           /* Restart the binary search, with new lower bound.  */
  1167.           continue;
  1168.         }
  1169.  
  1170.       cmp = (HOST_WIDE_INT) DECL_NAME (field) - (HOST_WIDE_INT) component;
  1171.       if (cmp == 0)
  1172.         break;
  1173.       if (cmp < 0)
  1174.         bot += half;
  1175.       else
  1176.         top = bot + half;
  1177.     }
  1178.  
  1179.       if (DECL_NAME (field_array[bot]) == component)
  1180.     field = field_array[bot];
  1181.       else if (DECL_NAME (field) != component)
  1182.     field = 0;
  1183.     }
  1184.   else
  1185.     {
  1186.       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  1187.     {
  1188.       if (DECL_NAME (field) == NULL_TREE)
  1189.         {
  1190.           tree junk;
  1191.           tree anon = lookup_field (TREE_TYPE (field), component, &junk);
  1192.           if (anon != NULL_TREE)
  1193.         {
  1194.           *indirect = field;
  1195.           return anon;
  1196.         }
  1197.         }
  1198.  
  1199.       if (DECL_NAME (field) == component)
  1200.         break;
  1201.     }
  1202.     }
  1203.  
  1204.   *indirect = NULL_TREE;
  1205.   return field;
  1206. }
  1207.  
  1208. /* Make an expression to refer to the COMPONENT field of
  1209.    structure or union value DATUM.  COMPONENT is an IDENTIFIER_NODE.  */
  1210.  
  1211. tree
  1212. build_component_ref (datum, component)
  1213.      tree datum, component;
  1214. {
  1215.   register tree type = TREE_TYPE (datum);
  1216.   register enum tree_code code = TREE_CODE (type);
  1217.   register tree field = NULL;
  1218.   register tree ref;
  1219.  
  1220.   /* If DATUM is a COMPOUND_EXPR or COND_EXPR, move our reference inside it
  1221.      unless we are not to support things not strictly ANSI.  */
  1222.   switch (TREE_CODE (datum))
  1223.     {
  1224.     case COMPOUND_EXPR:
  1225.       {
  1226.     tree value = build_component_ref (TREE_OPERAND (datum, 1), component);
  1227.     return build (COMPOUND_EXPR, TREE_TYPE (value),
  1228.               TREE_OPERAND (datum, 0), value);
  1229.       }
  1230.     case COND_EXPR:
  1231.       return build_conditional_expr
  1232.     (TREE_OPERAND (datum, 0),
  1233.      build_component_ref (TREE_OPERAND (datum, 1), component),
  1234.      build_component_ref (TREE_OPERAND (datum, 2), component));
  1235.     }
  1236.  
  1237.   /* See if there is a field or component with name COMPONENT.  */
  1238.  
  1239.   if (code == RECORD_TYPE || code == UNION_TYPE)
  1240.     {
  1241.       tree indirect = 0;
  1242.  
  1243.       if (TYPE_SIZE (type) == 0)
  1244.     {
  1245.       incomplete_type_error (NULL_TREE, type);
  1246.       return error_mark_node;
  1247.     }
  1248.  
  1249.       field = lookup_field (type, component, &indirect);
  1250.  
  1251.       if (!field)
  1252.     {
  1253.       error (code == RECORD_TYPE
  1254.          ? "structure has no member named `%s'"
  1255.          : "union has no member named `%s'",
  1256.          IDENTIFIER_POINTER (component));
  1257.       return error_mark_node;
  1258.     }
  1259.       if (TREE_TYPE (field) == error_mark_node)
  1260.     return error_mark_node;
  1261.  
  1262.       /* If FIELD was found buried within an anonymous union,
  1263.      make one COMPONENT_REF to get that anonymous union,
  1264.      then fall thru to make a second COMPONENT_REF to get FIELD.  */
  1265.       if (indirect != 0)
  1266.     {
  1267.       ref = build (COMPONENT_REF, TREE_TYPE (indirect), datum, indirect);
  1268.       if (TREE_READONLY (datum) || TREE_READONLY (indirect))
  1269.         TREE_READONLY (ref) = 1;
  1270.       if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (indirect))
  1271.         TREE_THIS_VOLATILE (ref) = 1;
  1272.       datum = ref;
  1273.     }
  1274.  
  1275.       ref = build (COMPONENT_REF, TREE_TYPE (field), datum, field);
  1276.  
  1277.       if (TREE_READONLY (datum) || TREE_READONLY (field))
  1278.     TREE_READONLY (ref) = 1;
  1279.       if (TREE_THIS_VOLATILE (datum) || TREE_THIS_VOLATILE (field))
  1280.     TREE_THIS_VOLATILE (ref) = 1;
  1281.  
  1282.       return ref;
  1283.     }
  1284.   else if (code != ERROR_MARK)
  1285.     error ("request for member `%s' in something not a structure or union",
  1286.         IDENTIFIER_POINTER (component));
  1287.  
  1288.   return error_mark_node;
  1289. }
  1290.  
  1291. /* Given an expression PTR for a pointer, return an expression
  1292.    for the value pointed to.
  1293.    ERRORSTRING is the name of the operator to appear in error messages.  */
  1294.  
  1295. tree
  1296. build_indirect_ref (ptr, errorstring)
  1297.      tree ptr;
  1298.      char *errorstring;
  1299. {
  1300.   register tree pointer = default_conversion (ptr);
  1301.   register tree type = TREE_TYPE (pointer);
  1302.  
  1303.   if (TREE_CODE (type) == POINTER_TYPE)
  1304.     {
  1305.       if (TREE_CODE (pointer) == ADDR_EXPR
  1306.       && !flag_volatile
  1307.       && (TREE_TYPE (TREE_OPERAND (pointer, 0))
  1308.           == TREE_TYPE (type)))
  1309.     return TREE_OPERAND (pointer, 0);
  1310.       else
  1311.     {
  1312.       tree t = TREE_TYPE (type);
  1313.       register tree ref = build1 (INDIRECT_REF,
  1314.                       TYPE_MAIN_VARIANT (t), pointer);
  1315.  
  1316.       if (TYPE_SIZE (t) == 0 && TREE_CODE (t) != ARRAY_TYPE)
  1317.         {
  1318.           error ("dereferencing pointer to incomplete type");
  1319.           return error_mark_node;
  1320.         }
  1321.       if (TREE_CODE (t) == VOID_TYPE)
  1322.         warning ("dereferencing `void *' pointer");
  1323.  
  1324.       /* We *must* set TREE_READONLY when dereferencing a pointer to const,
  1325.          so that we get the proper error message if the result is used
  1326.          to assign to.  Also, &* is supposed to be a no-op.
  1327.          And ANSI C seems to specify that the type of the result
  1328.          should be the const type.  */
  1329.       /* A de-reference of a pointer to const is not a const.  It is valid
  1330.          to change it via some other pointer.  */
  1331.       TREE_READONLY (ref) = TYPE_READONLY (t);
  1332.       TREE_SIDE_EFFECTS (ref)
  1333.         = TYPE_VOLATILE (t) || TREE_SIDE_EFFECTS (pointer) || flag_volatile;
  1334.       TREE_THIS_VOLATILE (ref) = TYPE_VOLATILE (t);
  1335.       return ref;
  1336.     }
  1337.     }
  1338.   else if (TREE_CODE (pointer) != ERROR_MARK)
  1339.     error ("invalid type argument of `%s'", errorstring);
  1340.   return error_mark_node;
  1341. }
  1342.  
  1343. /* This handles expressions of the form "a[i]", which denotes
  1344.    an array reference.
  1345.  
  1346.    This is logically equivalent in C to *(a+i), but we may do it differently.
  1347.    If A is a variable or a member, we generate a primitive ARRAY_REF.
  1348.    This avoids forcing the array out of registers, and can work on
  1349.    arrays that are not lvalues (for example, members of structures returned
  1350.    by functions).  */
  1351.  
  1352. tree
  1353. build_array_ref (array, index)
  1354.      tree array, index;
  1355. {
  1356.   if (index == 0)
  1357.     {
  1358.       error ("subscript missing in array reference");
  1359.       return error_mark_node;
  1360.     }
  1361.  
  1362.   if (TREE_TYPE (array) == error_mark_node
  1363.       || TREE_TYPE (index) == error_mark_node)
  1364.     return error_mark_node;
  1365.  
  1366.   if (TREE_CODE (TREE_TYPE (array)) == ARRAY_TYPE
  1367.       && TREE_CODE (array) != INDIRECT_REF)
  1368.     {
  1369.       tree rval, type;
  1370.  
  1371.       /* Subscripting with type char is likely to lose
  1372.      on a machine where chars are signed.
  1373.      So warn on any machine, but optionally.
  1374.      Don't warn for unsigned char since that type is safe.
  1375.      Don't warn for signed char because anyone who uses that
  1376.      must have done so deliberately.  */
  1377.       if (warn_char_subscripts
  1378.       && TYPE_MAIN_VARIANT (TREE_TYPE (index)) == char_type_node)
  1379.     warning ("array subscript has type `char'");
  1380.  
  1381.       /* Apply default promotions *after* noticing character types.  */
  1382.       index = default_conversion (index);
  1383.  
  1384.       /* Require integer *after* promotion, for sake of enums.  */
  1385.       if (TREE_CODE (TREE_TYPE (index)) != INTEGER_TYPE)
  1386.     {
  1387.       error ("array subscript is not an integer");
  1388.       return error_mark_node;
  1389.     }
  1390.  
  1391.       /* An array that is indexed by a non-constant
  1392.      cannot be stored in a register; we must be able to do
  1393.      address arithmetic on its address.
  1394.      Likewise an array of elements of variable size.  */
  1395.       if (TREE_CODE (index) != INTEGER_CST
  1396.       || (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array))) != 0
  1397.           && TREE_CODE (TYPE_SIZE (TREE_TYPE (TREE_TYPE (array)))) != INTEGER_CST))
  1398.     {
  1399.       if (mark_addressable (array) == 0)
  1400.         return error_mark_node;
  1401.     }
  1402.       /* An array that is indexed by a constant value which is not within
  1403.      the array bounds cannot be stored in a register either; because we
  1404.      would get a crash in store_bit_field/extract_bit_field when trying
  1405.      to access a non-existent part of the register.  */
  1406.       if (TREE_CODE (index) == INTEGER_CST
  1407.       && TYPE_VALUES (TREE_TYPE (array))
  1408.       && ! int_fits_type_p (index, TYPE_VALUES (TREE_TYPE (array))))
  1409.     {
  1410.       if (mark_addressable (array) == 0)
  1411.         return error_mark_node;
  1412.     }
  1413.  
  1414.       if (pedantic && !lvalue_p (array))
  1415.     {
  1416.       if (DECL_REGISTER (array))
  1417.         pedwarn ("ANSI C forbids subscripting `register' array");
  1418.       else
  1419.         pedwarn ("ANSI C forbids subscripting non-lvalue array");
  1420.     }
  1421.  
  1422.       if (pedantic)
  1423.     {
  1424.       tree foo = array;
  1425.       while (TREE_CODE (foo) == COMPONENT_REF)
  1426.         foo = TREE_OPERAND (foo, 0);
  1427.       if (TREE_CODE (foo) == VAR_DECL && DECL_REGISTER (foo))
  1428.         pedwarn ("ANSI C forbids subscripting non-lvalue array");
  1429.     }
  1430.  
  1431.       type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (array)));
  1432.       rval = build (ARRAY_REF, type, array, index);
  1433.       /* Array ref is const/volatile if the array elements are
  1434.          or if the array is.  */
  1435.       TREE_READONLY (rval)
  1436.     |= (TYPE_READONLY (TREE_TYPE (TREE_TYPE (array)))
  1437.         | TREE_READONLY (array));
  1438.       TREE_SIDE_EFFECTS (rval)
  1439.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1440.         | TREE_SIDE_EFFECTS (array));
  1441.       TREE_THIS_VOLATILE (rval)
  1442.     |= (TYPE_VOLATILE (TREE_TYPE (TREE_TYPE (array)))
  1443.         /* This was added by rms on 16 Nov 91.
  1444.            It fixes  vol struct foo *a;  a->elts[1] 
  1445.            in an inline function.
  1446.            Hope it doesn't break something else.  */
  1447.         | TREE_THIS_VOLATILE (array));
  1448.       return require_complete_type (fold (rval));
  1449.     }
  1450.  
  1451.   {
  1452.     tree ar = default_conversion (array);
  1453.     tree ind = default_conversion (index);
  1454.  
  1455.     /* Put the integer in IND to simplify error checking.  */
  1456.     if (TREE_CODE (TREE_TYPE (ar)) == INTEGER_TYPE)
  1457.       {
  1458.     tree temp = ar;
  1459.     ar = ind;
  1460.     ind = temp;
  1461.       }
  1462.  
  1463.     if (ar == error_mark_node)
  1464.       return ar;
  1465.  
  1466.     if (TREE_CODE (TREE_TYPE (ar)) != POINTER_TYPE)
  1467.       {
  1468.     error ("subscripted value is neither array nor pointer");
  1469.     return error_mark_node;
  1470.       }
  1471.     if (TREE_CODE (TREE_TYPE (ind)) != INTEGER_TYPE)
  1472.       {
  1473.     error ("array subscript is not an integer");
  1474.     return error_mark_node;
  1475.       }
  1476.  
  1477.     return build_indirect_ref (build_binary_op (PLUS_EXPR, ar, ind, 0),
  1478.                    "array indexing");
  1479.   }
  1480. }
  1481.  
  1482. /* Build a function call to function FUNCTION with parameters PARAMS.
  1483.    PARAMS is a list--a chain of TREE_LIST nodes--in which the
  1484.    TREE_VALUE of each node is a parameter-expression.
  1485.    FUNCTION's data type may be a function type or a pointer-to-function.  */
  1486.  
  1487. tree
  1488. build_function_call (function, params)
  1489.      tree function, params;
  1490. {
  1491.   register tree fntype, fundecl = 0;
  1492.   register tree coerced_params;
  1493.   tree name = NULL_TREE, assembler_name = NULL_TREE;
  1494.  
  1495.   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
  1496.   STRIP_TYPE_NOPS (function);
  1497.  
  1498.   /* Convert anything with function type to a pointer-to-function.  */
  1499.   if (TREE_CODE (function) == FUNCTION_DECL)
  1500.     {
  1501.       name = DECL_NAME (function);
  1502.       assembler_name = DECL_ASSEMBLER_NAME (function);
  1503.  
  1504.       /* Differs from default_conversion by not setting TREE_ADDRESSABLE
  1505.      (because calling an inline function does not mean the function
  1506.      needs to be separately compiled).  */
  1507.       fntype = build_type_variant (TREE_TYPE (function),
  1508.                    TREE_READONLY (function),
  1509.                    TREE_THIS_VOLATILE (function));
  1510.       fundecl = function;
  1511.       function = build1 (ADDR_EXPR, build_pointer_type (fntype), function);
  1512.     }
  1513.   else
  1514.     function = default_conversion (function);
  1515.  
  1516.   fntype = TREE_TYPE (function);
  1517.  
  1518.   if (TREE_CODE (fntype) == ERROR_MARK)
  1519.     return error_mark_node;
  1520.  
  1521.   if (!(TREE_CODE (fntype) == POINTER_TYPE
  1522.     && TREE_CODE (TREE_TYPE (fntype)) == FUNCTION_TYPE))
  1523.     {
  1524.       error ("called object is not a function");
  1525.       return error_mark_node;
  1526.     }
  1527.  
  1528.   /* fntype now gets the type of function pointed to.  */
  1529.   fntype = TREE_TYPE (fntype);
  1530.  
  1531.   /* Convert the parameters to the types declared in the
  1532.      function prototype, or apply default promotions.  */
  1533.  
  1534.   coerced_params
  1535.     = convert_arguments (TYPE_ARG_TYPES (fntype), params, name, fundecl);
  1536.  
  1537.   /* Check for errors in format strings.  */
  1538.  
  1539.   if (warn_format && (name || assembler_name))
  1540.     check_function_format (name, assembler_name, coerced_params);
  1541.  
  1542.   /* Recognize certain built-in functions so we can make tree-codes
  1543.      other than CALL_EXPR.  We do this when it enables fold-const.c
  1544.      to do something useful.  */
  1545.  
  1546.   if (TREE_CODE (function) == ADDR_EXPR
  1547.       && TREE_CODE (TREE_OPERAND (function, 0)) == FUNCTION_DECL
  1548.       && DECL_BUILT_IN (TREE_OPERAND (function, 0)))
  1549.     switch (DECL_FUNCTION_CODE (TREE_OPERAND (function, 0)))
  1550.       {
  1551.       case BUILT_IN_ABS:
  1552.       case BUILT_IN_LABS:
  1553.       case BUILT_IN_FABS:
  1554.     if (coerced_params == 0)
  1555.       return integer_zero_node;
  1556.     return build_unary_op (ABS_EXPR, TREE_VALUE (coerced_params), 0);
  1557.       }
  1558.  
  1559.   {
  1560.     register tree result
  1561.       = build (CALL_EXPR, TREE_TYPE (fntype),
  1562.            function, coerced_params, NULL_TREE);
  1563.  
  1564.     TREE_SIDE_EFFECTS (result) = 1;
  1565.     if (TREE_TYPE (result) == void_type_node)
  1566.       return result;
  1567.     return require_complete_type (result);
  1568.   }
  1569. }
  1570.  
  1571. /* Convert the argument expressions in the list VALUES
  1572.    to the types in the list TYPELIST.  The result is a list of converted
  1573.    argument expressions.
  1574.  
  1575.    If TYPELIST is exhausted, or when an element has NULL as its type,
  1576.    perform the default conversions.
  1577.  
  1578.    PARMLIST is the chain of parm decls for the function being called.
  1579.    It may be 0, if that info is not available.
  1580.    It is used only for generating error messages.
  1581.  
  1582.    NAME is an IDENTIFIER_NODE or 0.  It is used only for error messages.
  1583.  
  1584.    This is also where warnings about wrong number of args are generated.
  1585.  
  1586.    Both VALUES and the returned value are chains of TREE_LIST nodes
  1587.    with the elements of the list in the TREE_VALUE slots of those nodes.  */
  1588.  
  1589. static tree
  1590. convert_arguments (typelist, values, name, fundecl)
  1591.      tree typelist, values, name, fundecl;
  1592. {
  1593.   register tree typetail, valtail;
  1594.   register tree result = NULL;
  1595.   int parmnum;
  1596.  
  1597.   /* Scan the given expressions and types, producing individual
  1598.      converted arguments and pushing them on RESULT in reverse order.  */
  1599.  
  1600.   for (valtail = values, typetail = typelist, parmnum = 0;
  1601.        valtail;
  1602.        valtail = TREE_CHAIN (valtail), parmnum++)
  1603.     {
  1604.       register tree type = typetail ? TREE_VALUE (typetail) : 0;
  1605.       register tree val = TREE_VALUE (valtail);
  1606.  
  1607.       if (type == void_type_node)
  1608.     {
  1609.       if (name)
  1610.         error ("too many arguments to function `%s'",
  1611.            IDENTIFIER_POINTER (name));
  1612.       else
  1613.         error ("too many arguments to function");
  1614.       break;
  1615.     }
  1616.  
  1617.       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  1618.       /* Do not use STRIP_NOPS here!  We do not want an enumerator with value 0
  1619.      to convert automatically to a pointer.  */
  1620.       if (TREE_CODE (val) == NON_LVALUE_EXPR)
  1621.     val = TREE_OPERAND (val, 0);
  1622.  
  1623.       if (TREE_CODE (TREE_TYPE (val)) == ARRAY_TYPE
  1624.       || TREE_CODE (TREE_TYPE (val)) == FUNCTION_TYPE)
  1625.     val = default_conversion (val);
  1626.  
  1627.       val = require_complete_type (val);
  1628.  
  1629.       if (type != 0)
  1630.     {
  1631.       /* Formal parm type is specified by a function prototype.  */
  1632.       tree parmval;
  1633.  
  1634.       if (TYPE_SIZE (type) == 0)
  1635.         {
  1636.           error ("type of formal parameter %d is incomplete", parmnum + 1);
  1637.           parmval = val;
  1638.         }
  1639.       else
  1640.         {
  1641.           /* Optionally warn about conversions that
  1642.          differ from the default conversions.  */
  1643.           if (warn_conversion)
  1644.         {
  1645.           int formal_prec = TYPE_PRECISION (type);
  1646.  
  1647.           if (INTEGRAL_TYPE_P (type)
  1648.               && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
  1649.             warn_for_assignment ("%s as integer rather than floating due to prototype", (char *) 0, name, parmnum + 1);
  1650.           else if (TREE_CODE (type) == COMPLEX_TYPE
  1651.                && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
  1652.             warn_for_assignment ("%s as complex rather than floating due to prototype", (char *) 0, name, parmnum + 1);
  1653.           else if (TREE_CODE (type) == REAL_TYPE
  1654.                && INTEGRAL_TYPE_P (TREE_TYPE (val)))
  1655.             warn_for_assignment ("%s as floating rather than integer due to prototype", (char *) 0, name, parmnum + 1);
  1656.           else if (TREE_CODE (type) == REAL_TYPE
  1657.                && TREE_CODE (TREE_TYPE (val)) == COMPLEX_TYPE)
  1658.             warn_for_assignment ("%s as floating rather than complex due to prototype", (char *) 0, name, parmnum + 1);
  1659.           /* ??? At some point, messages should be written about
  1660.              conversions between complex types, but that's too messy
  1661.              to do now.  */
  1662.           else if (TREE_CODE (type) == REAL_TYPE
  1663.                && TREE_CODE (TREE_TYPE (val)) == REAL_TYPE)
  1664.             {
  1665.               /* Warn if any argument is passed as `float',
  1666.              since without a prototype it would be `double'.  */
  1667.               if (formal_prec == TYPE_PRECISION (float_type_node))
  1668.             warn_for_assignment ("%s as `float' rather than `double' due to prototype", (char *) 0, name, parmnum + 1);
  1669.             }
  1670.           /* Detect integer changing in width or signedness.  */
  1671.           else if (INTEGRAL_TYPE_P (type)
  1672.                && INTEGRAL_TYPE_P (TREE_TYPE (val)))
  1673.             {
  1674.               tree would_have_been = default_conversion (val);
  1675.               tree type1 = TREE_TYPE (would_have_been);
  1676.  
  1677.               if (TREE_CODE (type) == ENUMERAL_TYPE
  1678.               && type == TREE_TYPE (val))
  1679.             /* No warning if function asks for enum
  1680.                and the actual arg is that enum type.  */
  1681.             ;
  1682.               else if (formal_prec != TYPE_PRECISION (type1))
  1683.             warn_for_assignment ("%s with different width due to prototype", (char *) 0, name, parmnum + 1);
  1684.               else if (TREE_UNSIGNED (type) == TREE_UNSIGNED (type1))
  1685.             ;
  1686.               /* Don't complain if the formal parameter type
  1687.              is an enum, because we can't tell now whether
  1688.              the value was an enum--even the same enum.  */
  1689.               else if (TREE_CODE (type) == ENUMERAL_TYPE)
  1690.             ;
  1691.               else if (TREE_CODE (val) == INTEGER_CST
  1692.                    && int_fits_type_p (val, type))
  1693.             /* Change in signedness doesn't matter
  1694.                if a constant value is unaffected.  */
  1695.             ;
  1696.               /* Likewise for a constant in a NOP_EXPR.  */
  1697.               else if (TREE_CODE (val) == NOP_EXPR
  1698.                    && TREE_CODE (TREE_OPERAND (val, 0)) == INTEGER_CST
  1699.                    && int_fits_type_p (TREE_OPERAND (val, 0), type))
  1700.             ;
  1701. #if 0 /* We never get such tree structure here.  */
  1702.               else if (TREE_CODE (TREE_TYPE (val)) == ENUMERAL_TYPE
  1703.                    && int_fits_type_p (TYPE_MIN_VALUE (TREE_TYPE (val)), type)
  1704.                    && int_fits_type_p (TYPE_MAX_VALUE (TREE_TYPE (val)), type))
  1705.             /* Change in signedness doesn't matter
  1706.                if an enum value is unaffected.  */
  1707.             ;
  1708. #endif
  1709.               /* If the value is extended from a narrower
  1710.              unsigned type, it doesn't matter whether we
  1711.              pass it as signed or unsigned; the value
  1712.              certainly is the same either way.  */
  1713.               else if (TYPE_PRECISION (TREE_TYPE (val)) < TYPE_PRECISION (type)
  1714.                    && TREE_UNSIGNED (TREE_TYPE (val)))
  1715.             ;
  1716.               else if (TREE_UNSIGNED (type))
  1717.             warn_for_assignment ("%s as unsigned due to prototype", (char *) 0, name, parmnum + 1);
  1718.               else
  1719.             warn_for_assignment ("%s as signed due to prototype", (char *) 0, name, parmnum + 1);
  1720.             }
  1721.         }
  1722.  
  1723.           parmval = convert_for_assignment (type, val, 
  1724.                             (char *)0, /* arg passing  */
  1725.                         fundecl, name, parmnum + 1);
  1726.           
  1727. #ifdef PROMOTE_PROTOTYPES
  1728.           if ((TREE_CODE (type) == INTEGER_TYPE
  1729.            || TREE_CODE (type) == ENUMERAL_TYPE)
  1730.           && (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)))
  1731.         parmval = default_conversion (parmval);
  1732. #endif
  1733.         }
  1734.       result = tree_cons (NULL_TREE, parmval, result);
  1735.     }
  1736.       else if (TREE_CODE (TREE_TYPE (val)) == REAL_TYPE
  1737.                && (TYPE_PRECISION (TREE_TYPE (val))
  1738.                < TYPE_PRECISION (double_type_node)))
  1739.     /* Convert `float' to `double'.  */
  1740.     result = tree_cons (NULL_TREE, convert (double_type_node, val), result);
  1741.       else
  1742.     /* Convert `short' and `char' to full-size `int'.  */
  1743.     result = tree_cons (NULL_TREE, default_conversion (val), result);
  1744.  
  1745.       if (typetail)
  1746.     typetail = TREE_CHAIN (typetail);
  1747.     }
  1748.  
  1749.   if (typetail != 0 && TREE_VALUE (typetail) != void_type_node)
  1750.     {
  1751.       if (name)
  1752.     error ("too few arguments to function `%s'",
  1753.            IDENTIFIER_POINTER (name));
  1754.       else
  1755.     error ("too few arguments to function");
  1756.     }
  1757.  
  1758.   return nreverse (result);
  1759. }
  1760.  
  1761. /* This is the entry point used by the parser
  1762.    for binary operators in the input.
  1763.    In addition to constructing the expression,
  1764.    we check for operands that were written with other binary operators
  1765.    in a way that is likely to confuse the user.  */
  1766.  
  1767. tree
  1768. parser_build_binary_op (code, arg1, arg2)
  1769.      enum tree_code code;
  1770.      tree arg1, arg2;
  1771. {
  1772.   tree result = build_binary_op (code, arg1, arg2, 1);
  1773.  
  1774.   char class;
  1775.   char class1 = TREE_CODE_CLASS (TREE_CODE (arg1));
  1776.   char class2 = TREE_CODE_CLASS (TREE_CODE (arg2));
  1777.   enum tree_code code1 = ERROR_MARK;
  1778.   enum tree_code code2 = ERROR_MARK;
  1779.  
  1780.   if (class1 == 'e' || class1 == '1'
  1781.       || class1 == '2' || class1 == '<')
  1782.     code1 = C_EXP_ORIGINAL_CODE (arg1);
  1783.   if (class2 == 'e' || class2 == '1'
  1784.       || class2 == '2' || class2 == '<')
  1785.     code2 = C_EXP_ORIGINAL_CODE (arg2);
  1786.  
  1787.   /* Check for cases such as x+y<<z which users are likely
  1788.      to misinterpret.  If parens are used, C_EXP_ORIGINAL_CODE
  1789.      is cleared to prevent these warnings.  */
  1790.   if (warn_parentheses)
  1791.     {
  1792.       if (code == LSHIFT_EXPR || code == RSHIFT_EXPR)
  1793.     {
  1794.       if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1795.           || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1796.         warning ("suggest parentheses around + or - inside shift");
  1797.     }
  1798.  
  1799.       if (code == TRUTH_ORIF_EXPR)
  1800.     {
  1801.       if (code1 == TRUTH_ANDIF_EXPR
  1802.           || code2 == TRUTH_ANDIF_EXPR)
  1803.         warning ("suggest parentheses around && within ||");
  1804.     }
  1805.  
  1806.       if (code == BIT_IOR_EXPR)
  1807.     {
  1808.       if (code1 == BIT_AND_EXPR || code1 == BIT_XOR_EXPR
  1809.           || code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1810.           || code2 == BIT_AND_EXPR || code2 == BIT_XOR_EXPR
  1811.           || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1812.         warning ("suggest parentheses around arithmetic in operand of |");
  1813.     }
  1814.  
  1815.       if (code == BIT_XOR_EXPR)
  1816.     {
  1817.       if (code1 == BIT_AND_EXPR
  1818.           || code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1819.           || code2 == BIT_AND_EXPR
  1820.           || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1821.         warning ("suggest parentheses around arithmetic in operand of ^");
  1822.     }
  1823.  
  1824.       if (code == BIT_AND_EXPR)
  1825.     {
  1826.       if (code1 == PLUS_EXPR || code1 == MINUS_EXPR
  1827.           || code2 == PLUS_EXPR || code2 == MINUS_EXPR)
  1828.         warning ("suggest parentheses around + or - in operand of &");
  1829.     }
  1830.     }
  1831.  
  1832.   /* Similarly, check for cases like 1<=i<=10 that are probably errors.  */
  1833.   if (TREE_CODE_CLASS (code) == '<' && extra_warnings
  1834.       && (TREE_CODE_CLASS (code1) == '<' || TREE_CODE_CLASS (code2) == '<'))
  1835.     warning ("comparisons like X<=Y<=Z do not have their mathematical meaning");
  1836.  
  1837.   unsigned_conversion_warning (result, arg1);
  1838.   unsigned_conversion_warning (result, arg2);
  1839.   overflow_warning (result);
  1840.  
  1841.   class = TREE_CODE_CLASS (TREE_CODE (result));
  1842.  
  1843.   /* Record the code that was specified in the source,
  1844.      for the sake of warnings about confusing nesting.  */
  1845.   if (class == 'e' || class == '1'
  1846.       || class == '2' || class == '<')
  1847.     C_SET_EXP_ORIGINAL_CODE (result, code);
  1848.   else
  1849.     {
  1850.       int flag = TREE_CONSTANT (result);
  1851.       /* We used to use NOP_EXPR rather than NON_LVALUE_EXPR
  1852.      so that convert_for_assignment wouldn't strip it.
  1853.      That way, we got warnings for things like p = (1 - 1).
  1854.      But it turns out we should not get those warnings.  */
  1855.       result = build1 (NON_LVALUE_EXPR, TREE_TYPE (result), result);
  1856.       C_SET_EXP_ORIGINAL_CODE (result, code);
  1857.       TREE_CONSTANT (result) = flag;
  1858.     }
  1859.  
  1860.   return result;
  1861. }
  1862.  
  1863. /* Build a binary-operation expression without default conversions.
  1864.    CODE is the kind of expression to build.
  1865.    This function differs from `build' in several ways:
  1866.    the data type of the result is computed and recorded in it,
  1867.    warnings are generated if arg data types are invalid,
  1868.    special handling for addition and subtraction of pointers is known,
  1869.    and some optimization is done (operations on narrow ints
  1870.    are done in the narrower type when that gives the same result).
  1871.    Constant folding is also done before the result is returned.
  1872.  
  1873.    Note that the operands will never have enumeral types, or function
  1874.    or array types, because either they will have the default conversions
  1875.    performed or they have both just been converted to some other type in which
  1876.    the arithmetic is to be done.  */
  1877.  
  1878. tree
  1879. build_binary_op (code, orig_op0, orig_op1, convert_p)
  1880.      enum tree_code code;
  1881.      tree orig_op0, orig_op1;
  1882.      int convert_p;
  1883. {
  1884.   tree type0, type1;
  1885.   register enum tree_code code0, code1;
  1886.   tree op0, op1;
  1887.  
  1888.   /* Expression code to give to the expression when it is built.
  1889.      Normally this is CODE, which is what the caller asked for,
  1890.      but in some special cases we change it.  */
  1891.   register enum tree_code resultcode = code;
  1892.  
  1893.   /* Data type in which the computation is to be performed.
  1894.      In the simplest cases this is the common type of the arguments.  */
  1895.   register tree result_type = NULL;
  1896.  
  1897.   /* Nonzero means operands have already been type-converted
  1898.      in whatever way is necessary.
  1899.      Zero means they need to be converted to RESULT_TYPE.  */
  1900.   int converted = 0;
  1901.  
  1902.   /* Nonzero means create the expression with this type, rather than
  1903.      RESULT_TYPE.  */
  1904.   tree build_type = 0;
  1905.  
  1906.   /* Nonzero means after finally constructing the expression
  1907.      convert it to this type.  */
  1908.   tree final_type = 0;
  1909.  
  1910.   /* Nonzero if this is an operation like MIN or MAX which can
  1911.      safely be computed in short if both args are promoted shorts.
  1912.      Also implies COMMON.
  1913.      -1 indicates a bitwise operation; this makes a difference
  1914.      in the exact conditions for when it is safe to do the operation
  1915.      in a narrower mode.  */
  1916.   int shorten = 0;
  1917.  
  1918.   /* Nonzero if this is a comparison operation;
  1919.      if both args are promoted shorts, compare the original shorts.
  1920.      Also implies COMMON.  */
  1921.   int short_compare = 0;
  1922.  
  1923.   /* Nonzero if this is a right-shift operation, which can be computed on the
  1924.      original short and then promoted if the operand is a promoted short.  */
  1925.   int short_shift = 0;
  1926.  
  1927.   /* Nonzero means set RESULT_TYPE to the common type of the args.  */
  1928.   int common = 0;
  1929.  
  1930.   if (convert_p)
  1931.     {
  1932.       op0 = default_conversion (orig_op0);
  1933.       op1 = default_conversion (orig_op1);
  1934.     }
  1935.   else
  1936.     {
  1937.       op0 = orig_op0;
  1938.       op1 = orig_op1;
  1939.     }
  1940.  
  1941.   type0 = TREE_TYPE (op0);
  1942.   type1 = TREE_TYPE (op1);
  1943.  
  1944.   /* The expression codes of the data types of the arguments tell us
  1945.      whether the arguments are integers, floating, pointers, etc.  */
  1946.   code0 = TREE_CODE (type0);
  1947.   code1 = TREE_CODE (type1);
  1948.  
  1949.   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
  1950.   STRIP_TYPE_NOPS (op0);
  1951.   STRIP_TYPE_NOPS (op1);
  1952.  
  1953.   /* If an error was already reported for one of the arguments,
  1954.      avoid reporting another error.  */
  1955.  
  1956.   if (code0 == ERROR_MARK || code1 == ERROR_MARK)
  1957.     return error_mark_node;
  1958.  
  1959.   switch (code)
  1960.     {
  1961.     case PLUS_EXPR:
  1962.       /* Handle the pointer + int case.  */
  1963.       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1964.     return pointer_int_sum (PLUS_EXPR, op0, op1);
  1965.       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
  1966.     return pointer_int_sum (PLUS_EXPR, op1, op0);
  1967.       else
  1968.     common = 1;
  1969.       break;
  1970.  
  1971.     case MINUS_EXPR:
  1972.       /* Subtraction of two similar pointers.
  1973.      We must subtract them as integers, then divide by object size.  */
  1974.       if (code0 == POINTER_TYPE && code1 == POINTER_TYPE
  1975.       && comp_target_types (type0, type1))
  1976.     return pointer_diff (op0, op1);
  1977.       /* Handle pointer minus int.  Just like pointer plus int.  */
  1978.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  1979.     return pointer_int_sum (MINUS_EXPR, op0, op1);
  1980.       else
  1981.     common = 1;
  1982.       break;
  1983.  
  1984.     case MULT_EXPR:
  1985.       common = 1;
  1986.       break;
  1987.  
  1988.     case TRUNC_DIV_EXPR:
  1989.     case CEIL_DIV_EXPR:
  1990.     case FLOOR_DIV_EXPR:
  1991.     case ROUND_DIV_EXPR:
  1992.     case EXACT_DIV_EXPR:
  1993.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
  1994.        || code0 == COMPLEX_TYPE)
  1995.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
  1996.           || code1 == COMPLEX_TYPE))
  1997.     {
  1998.       if (!(code0 == INTEGER_TYPE && code1 == INTEGER_TYPE))
  1999.         resultcode = RDIV_EXPR;
  2000.       else
  2001.         {
  2002.           /* Although it would be tempting to shorten always here, that
  2003.          loses on some targets, since the modulo instruction is
  2004.          undefined if the quotient can't be represented in the
  2005.          computation mode.  We shorten only if unsigned or if
  2006.          dividing by something we know != -1.  */
  2007.           shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
  2008.              || (TREE_CODE (op1) == INTEGER_CST
  2009.                  && (TREE_INT_CST_LOW (op1) != -1
  2010.                  || TREE_INT_CST_HIGH (op1) != -1)));
  2011.         }
  2012.       common = 1;
  2013.     }
  2014.       break;
  2015.  
  2016.     case BIT_AND_EXPR:
  2017.     case BIT_ANDTC_EXPR:
  2018.     case BIT_IOR_EXPR:
  2019.     case BIT_XOR_EXPR:
  2020.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2021.     shorten = -1;
  2022.       /* If one operand is a constant, and the other is a short type
  2023.      that has been converted to an int,
  2024.      really do the work in the short type and then convert the
  2025.      result to int.  If we are lucky, the constant will be 0 or 1
  2026.      in the short type, making the entire operation go away.  */
  2027.       if (TREE_CODE (op0) == INTEGER_CST
  2028.       && TREE_CODE (op1) == NOP_EXPR
  2029.       && TYPE_PRECISION (type1) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op1, 0)))
  2030.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op1, 0))))
  2031.     {
  2032.       final_type = result_type;
  2033.       op1 = TREE_OPERAND (op1, 0);
  2034.       result_type = TREE_TYPE (op1);
  2035.     }
  2036.       if (TREE_CODE (op1) == INTEGER_CST
  2037.       && TREE_CODE (op0) == NOP_EXPR
  2038.       && TYPE_PRECISION (type0) > TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (op0, 0)))
  2039.       && TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (op0, 0))))
  2040.     {
  2041.       final_type = result_type;
  2042.       op0 = TREE_OPERAND (op0, 0);
  2043.       result_type = TREE_TYPE (op0);
  2044.     }
  2045.       break;
  2046.  
  2047.     case TRUNC_MOD_EXPR:
  2048.     case FLOOR_MOD_EXPR:
  2049.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2050.     {
  2051.       /* Although it would be tempting to shorten always here, that loses
  2052.          on some targets, since the modulo instruction is undefined if the
  2053.          quotient can't be represented in the computation mode.  We shorten
  2054.          only if unsigned or if dividing by something we know != -1.  */
  2055.       shorten = (TREE_UNSIGNED (TREE_TYPE (orig_op0))
  2056.              || (TREE_CODE (op1) == INTEGER_CST
  2057.              && (TREE_INT_CST_LOW (op1) != -1
  2058.                  || TREE_INT_CST_HIGH (op1) != -1)));
  2059.       common = 1;
  2060.     }
  2061.       break;
  2062.  
  2063.     case TRUTH_ANDIF_EXPR:
  2064.     case TRUTH_ORIF_EXPR:
  2065.     case TRUTH_AND_EXPR:
  2066.     case TRUTH_OR_EXPR:
  2067.     case TRUTH_XOR_EXPR:
  2068.       if ((code0 == INTEGER_TYPE || code0 == POINTER_TYPE
  2069.        || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
  2070.       && (code1 == INTEGER_TYPE || code1 == POINTER_TYPE
  2071.           || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
  2072.     {
  2073.       /* Result of these operations is always an int,
  2074.          but that does not mean the operands should be
  2075.          converted to ints!  */
  2076.       result_type = integer_type_node;
  2077.       op0 = truthvalue_conversion (op0);
  2078.       op1 = truthvalue_conversion (op1);
  2079.       converted = 1;
  2080.     }
  2081.       break;
  2082.  
  2083.       /* Shift operations: result has same type as first operand;
  2084.      always convert second operand to int.
  2085.      Also set SHORT_SHIFT if shifting rightward.  */
  2086.  
  2087.     case RSHIFT_EXPR:
  2088.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2089.     {
  2090.       if (TREE_CODE (op1) == INTEGER_CST)
  2091.         {
  2092.           if (tree_int_cst_sgn (op1) < 0)
  2093.         warning ("right shift count is negative");
  2094.           else
  2095.         {
  2096.           if (TREE_INT_CST_LOW (op1) | TREE_INT_CST_HIGH (op1))
  2097.             short_shift = 1;
  2098.           if (TREE_INT_CST_HIGH (op1) != 0
  2099.               || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2100.               >= TYPE_PRECISION (type0)))
  2101.             warning ("right shift count >= width of type");
  2102.         }
  2103.         }
  2104.       /* Use the type of the value to be shifted.
  2105.          This is what most traditional C compilers do.  */
  2106.       result_type = type0;
  2107.       /* Unless traditional, convert the shift-count to an integer,
  2108.          regardless of size of value being shifted.  */
  2109.       if (! flag_traditional)
  2110.         {
  2111.           if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2112.         op1 = convert (integer_type_node, op1);
  2113.           /* Avoid converting op1 to result_type later.  */
  2114.           converted = 1;
  2115.         }
  2116.     }
  2117.       break;
  2118.  
  2119.     case LSHIFT_EXPR:
  2120.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2121.     {
  2122.       if (TREE_CODE (op1) == INTEGER_CST)
  2123.         {
  2124.           if (tree_int_cst_sgn (op1) < 0)
  2125.         warning ("left shift count is negative");
  2126.           else if (TREE_INT_CST_HIGH (op1) != 0
  2127.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2128.                >= TYPE_PRECISION (type0)))
  2129.         warning ("left shift count >= width of type");
  2130.         }
  2131.       /* Use the type of the value to be shifted.
  2132.          This is what most traditional C compilers do.  */
  2133.       result_type = type0;
  2134.       /* Unless traditional, convert the shift-count to an integer,
  2135.          regardless of size of value being shifted.  */
  2136.       if (! flag_traditional)
  2137.         {
  2138.           if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2139.         op1 = convert (integer_type_node, op1);
  2140.           /* Avoid converting op1 to result_type later.  */
  2141.           converted = 1;
  2142.         }
  2143.     }
  2144.       break;
  2145.  
  2146.     case RROTATE_EXPR:
  2147.     case LROTATE_EXPR:
  2148.       if (code0 == INTEGER_TYPE && code1 == INTEGER_TYPE)
  2149.     {
  2150.       if (TREE_CODE (op1) == INTEGER_CST)
  2151.         {
  2152.           if (tree_int_cst_sgn (op1) < 0)
  2153.         warning ("shift count is negative");
  2154.           else if (TREE_INT_CST_HIGH (op1) != 0
  2155.                || ((unsigned HOST_WIDE_INT) TREE_INT_CST_LOW (op1)
  2156.                >= TYPE_PRECISION (type0)))
  2157.         warning ("shift count >= width of type");
  2158.         }
  2159.       /* Use the type of the value to be shifted.
  2160.          This is what most traditional C compilers do.  */
  2161.       result_type = type0;
  2162.       /* Unless traditional, convert the shift-count to an integer,
  2163.          regardless of size of value being shifted.  */
  2164.       if (! flag_traditional)
  2165.         {
  2166.           if (TYPE_MAIN_VARIANT (TREE_TYPE (op1)) != integer_type_node)
  2167.         op1 = convert (integer_type_node, op1);
  2168.           /* Avoid converting op1 to result_type later.  */
  2169.           converted = 1;
  2170.         }
  2171.     }
  2172.       break;
  2173.  
  2174.     case EQ_EXPR:
  2175.     case NE_EXPR:
  2176.       /* Result of comparison is always int,
  2177.      but don't convert the args to int!  */
  2178.       build_type = integer_type_node;
  2179.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE
  2180.        || code0 == COMPLEX_TYPE)
  2181.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE
  2182.           || code1 == COMPLEX_TYPE))
  2183.     short_compare = 1;
  2184.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2185.     {
  2186.       register tree tt0 = TREE_TYPE (type0);
  2187.       register tree tt1 = TREE_TYPE (type1);
  2188.       /* Anything compares with void *.  void * compares with anything.
  2189.          Otherwise, the targets must be compatible
  2190.          and both must be object or both incomplete.  */
  2191.       if (comp_target_types (type0, type1))
  2192.         result_type = common_type (type0, type1);
  2193.       else if (TYPE_MAIN_VARIANT (tt0) == void_type_node)
  2194.         {
  2195.           /* op0 != orig_op0 detects the case of something
  2196.          whose value is 0 but which isn't a valid null ptr const.  */
  2197.           if (pedantic && (!integer_zerop (op0) || op0 != orig_op0)
  2198.           && TREE_CODE (tt1) == FUNCTION_TYPE)
  2199.         pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
  2200.         }
  2201.       else if (TYPE_MAIN_VARIANT (tt1) == void_type_node)
  2202.         {
  2203.           if (pedantic && (!integer_zerop (op1) || op1 != orig_op1)
  2204.           && TREE_CODE (tt0) == FUNCTION_TYPE)
  2205.         pedwarn ("ANSI C forbids comparison of `void *' with function pointer");
  2206.         }
  2207.       else
  2208.         pedwarn ("comparison of distinct pointer types lacks a cast");
  2209.  
  2210.       if (result_type == NULL_TREE)
  2211.         result_type = ptr_type_node;
  2212.     }
  2213.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  2214.            && integer_zerop (op1))
  2215.     result_type = type0;
  2216.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  2217.            && integer_zerop (op0))
  2218.     result_type = type1;
  2219.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2220.     {
  2221.       result_type = type0;
  2222.       if (! flag_traditional)
  2223.         pedwarn ("comparison between pointer and integer");
  2224.     }
  2225.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  2226.     {
  2227.       result_type = type1;
  2228.       if (! flag_traditional)
  2229.         pedwarn ("comparison between pointer and integer");
  2230.     }
  2231.       break;
  2232.  
  2233.     case MAX_EXPR:
  2234.     case MIN_EXPR:
  2235.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2236.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2237.     shorten = 1;
  2238.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2239.     {
  2240.       if (comp_target_types (type0, type1))
  2241.         {
  2242.           result_type = common_type (type0, type1);
  2243.           if (pedantic 
  2244.           && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  2245.         pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
  2246.         }
  2247.       else
  2248.         {
  2249.           result_type = ptr_type_node;
  2250.           pedwarn ("comparison of distinct pointer types lacks a cast");
  2251.         }
  2252.     }
  2253.       break;
  2254.  
  2255.     case LE_EXPR:
  2256.     case GE_EXPR:
  2257.     case LT_EXPR:
  2258.     case GT_EXPR:
  2259.       build_type = integer_type_node;
  2260.       if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE)
  2261.       && (code1 == INTEGER_TYPE || code1 == REAL_TYPE))
  2262.     short_compare = 1;
  2263.       else if (code0 == POINTER_TYPE && code1 == POINTER_TYPE)
  2264.     {
  2265.       if (comp_target_types (type0, type1))
  2266.         {
  2267.           result_type = common_type (type0, type1);
  2268.           if ((TYPE_SIZE (TREE_TYPE (type0)) != 0)
  2269.           != (TYPE_SIZE (TREE_TYPE (type1)) != 0))
  2270.         pedwarn ("comparison of complete and incomplete pointers");
  2271.           else if (pedantic 
  2272.                && TREE_CODE (TREE_TYPE (type0)) == FUNCTION_TYPE)
  2273.         pedwarn ("ANSI C forbids ordered comparisons of pointers to functions");
  2274.         }
  2275.       else
  2276.         {
  2277.           result_type = ptr_type_node;
  2278.           pedwarn ("comparison of distinct pointer types lacks a cast");
  2279.         }
  2280.     }
  2281.       else if (code0 == POINTER_TYPE && TREE_CODE (op1) == INTEGER_CST
  2282.            && integer_zerop (op1))
  2283.     {
  2284.       result_type = type0;
  2285.       if (pedantic || extra_warnings)
  2286.         pedwarn ("ordered comparison of pointer with integer zero");
  2287.     }
  2288.       else if (code1 == POINTER_TYPE && TREE_CODE (op0) == INTEGER_CST
  2289.            && integer_zerop (op0))
  2290.     {
  2291.       result_type = type1;
  2292.       if (pedantic)
  2293.         pedwarn ("ordered comparison of pointer with integer zero");
  2294.     }
  2295.       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
  2296.     {
  2297.       result_type = type0;
  2298.       if (! flag_traditional)
  2299.         pedwarn ("comparison between pointer and integer");
  2300.     }
  2301.       else if (code0 == INTEGER_TYPE && code1 == POINTER_TYPE)
  2302.     {
  2303.       result_type = type1;
  2304.       if (! flag_traditional)
  2305.         pedwarn ("comparison between pointer and integer");
  2306.     }
  2307.       break;
  2308.     }
  2309.  
  2310.   if ((code0 == INTEGER_TYPE || code0 == REAL_TYPE || code0 == COMPLEX_TYPE)
  2311.       &&
  2312.       (code1 == INTEGER_TYPE || code1 == REAL_TYPE || code1 == COMPLEX_TYPE))
  2313.     {
  2314.       int none_complex = (code0 != COMPLEX_TYPE && code1 != COMPLEX_TYPE);
  2315.  
  2316.       if (shorten || common || short_compare)
  2317.     result_type = common_type (type0, type1);
  2318.  
  2319.       /* For certain operations (which identify themselves by shorten != 0)
  2320.      if both args were extended from the same smaller type,
  2321.      do the arithmetic in that type and then extend.
  2322.  
  2323.      shorten !=0 and !=1 indicates a bitwise operation.
  2324.      For them, this optimization is safe only if
  2325.      both args are zero-extended or both are sign-extended.
  2326.      Otherwise, we might change the result.
  2327.      Eg, (short)-1 | (unsigned short)-1 is (int)-1
  2328.      but calculated in (unsigned short) it would be (unsigned short)-1.  */
  2329.  
  2330.       if (shorten && none_complex)
  2331.     {
  2332.       int unsigned0, unsigned1;
  2333.       tree arg0 = get_narrower (op0, &unsigned0);
  2334.       tree arg1 = get_narrower (op1, &unsigned1);
  2335.       /* UNS is 1 if the operation to be done is an unsigned one.  */
  2336.       int uns = TREE_UNSIGNED (result_type);
  2337.       tree type;
  2338.  
  2339.       final_type = result_type;
  2340.  
  2341.       /* Handle the case that OP0 (or OP1) does not *contain* a conversion
  2342.          but it *requires* conversion to FINAL_TYPE.  */
  2343.  
  2344.       if ((TYPE_PRECISION (TREE_TYPE (op0))
  2345.            == TYPE_PRECISION (TREE_TYPE (arg0)))
  2346.           && TREE_TYPE (op0) != final_type)
  2347.         unsigned0 = TREE_UNSIGNED (TREE_TYPE (op0));
  2348.       if ((TYPE_PRECISION (TREE_TYPE (op1))
  2349.            == TYPE_PRECISION (TREE_TYPE (arg1)))
  2350.           && TREE_TYPE (op1) != final_type)
  2351.         unsigned1 = TREE_UNSIGNED (TREE_TYPE (op1));
  2352.  
  2353.       /* Now UNSIGNED0 is 1 if ARG0 zero-extends to FINAL_TYPE.  */
  2354.  
  2355.       /* For bitwise operations, signedness of nominal type
  2356.          does not matter.  Consider only how operands were extended.  */
  2357.       if (shorten == -1)
  2358.         uns = unsigned0;
  2359.  
  2360.       /* Note that in all three cases below we refrain from optimizing
  2361.          an unsigned operation on sign-extended args.
  2362.          That would not be valid.  */
  2363.  
  2364.       /* Both args variable: if both extended in same way
  2365.          from same width, do it in that width.
  2366.          Do it unsigned if args were zero-extended.  */
  2367.       if ((TYPE_PRECISION (TREE_TYPE (arg0))
  2368.            < TYPE_PRECISION (result_type))
  2369.           && (TYPE_PRECISION (TREE_TYPE (arg1))
  2370.           == TYPE_PRECISION (TREE_TYPE (arg0)))
  2371.           && unsigned0 == unsigned1
  2372.           && (unsigned0 || !uns))
  2373.         result_type
  2374.           = signed_or_unsigned_type (unsigned0,
  2375.                      common_type (TREE_TYPE (arg0), TREE_TYPE (arg1)));
  2376.       else if (TREE_CODE (arg0) == INTEGER_CST
  2377.            && (unsigned1 || !uns)
  2378.            && (TYPE_PRECISION (TREE_TYPE (arg1))
  2379.                < TYPE_PRECISION (result_type))
  2380.            && (type = signed_or_unsigned_type (unsigned1,
  2381.                                TREE_TYPE (arg1)),
  2382.                int_fits_type_p (arg0, type)))
  2383.         result_type = type;
  2384.       else if (TREE_CODE (arg1) == INTEGER_CST
  2385.            && (unsigned0 || !uns)
  2386.            && (TYPE_PRECISION (TREE_TYPE (arg0))
  2387.                < TYPE_PRECISION (result_type))
  2388.            && (type = signed_or_unsigned_type (unsigned0,
  2389.                                TREE_TYPE (arg0)),
  2390.                int_fits_type_p (arg1, type)))
  2391.         result_type = type;
  2392.     }
  2393.  
  2394.       /* Shifts can be shortened if shifting right.  */
  2395.  
  2396.       if (short_shift)
  2397.     {
  2398.       int unsigned_arg;
  2399.       tree arg0 = get_narrower (op0, &unsigned_arg);
  2400.  
  2401.       final_type = result_type;
  2402.  
  2403.       if (arg0 == op0 && final_type == TREE_TYPE (op0))
  2404.         unsigned_arg = TREE_UNSIGNED (TREE_TYPE (op0));
  2405.  
  2406.       if (TYPE_PRECISION (TREE_TYPE (arg0)) < TYPE_PRECISION (result_type)
  2407.           /* We can shorten only if the shift count is less than the
  2408.          number of bits in the smaller type size.  */
  2409.           && TREE_INT_CST_HIGH (op1) == 0
  2410.           && TYPE_PRECISION (TREE_TYPE (arg0)) > TREE_INT_CST_LOW (op1)
  2411.           /* If arg is sign-extended and then unsigned-shifted,
  2412.          we can simulate this with a signed shift in arg's type
  2413.          only if the extended result is at least twice as wide
  2414.          as the arg.  Otherwise, the shift could use up all the
  2415.          ones made by sign-extension and bring in zeros.
  2416.          We can't optimize that case at all, but in most machines
  2417.          it never happens because available widths are 2**N.  */
  2418.           && (!TREE_UNSIGNED (final_type)
  2419.           || unsigned_arg
  2420.           || 2 * TYPE_PRECISION (TREE_TYPE (arg0)) <= TYPE_PRECISION (result_type)))
  2421.         {
  2422.           /* Do an unsigned shift if the operand was zero-extended.  */
  2423.           result_type
  2424.         = signed_or_unsigned_type (unsigned_arg,
  2425.                        TREE_TYPE (arg0));
  2426.           /* Convert value-to-be-shifted to that type.  */
  2427.           if (TREE_TYPE (op0) != result_type)
  2428.         op0 = convert (result_type, op0);
  2429.           converted = 1;
  2430.         }
  2431.     }
  2432.  
  2433.       /* Comparison operations are shortened too but differently.
  2434.      They identify themselves by setting short_compare = 1.  */
  2435.  
  2436.       if (short_compare)
  2437.     {
  2438.       /* Don't write &op0, etc., because that would prevent op0
  2439.          from being kept in a register.
  2440.          Instead, make copies of the our local variables and
  2441.          pass the copies by reference, then copy them back afterward.  */
  2442.       tree xop0 = op0, xop1 = op1, xresult_type = result_type;
  2443.       enum tree_code xresultcode = resultcode;
  2444.       tree val 
  2445.         = shorten_compare (&xop0, &xop1, &xresult_type, &xresultcode);
  2446.       if (val != 0)
  2447.         return val;
  2448.       op0 = xop0, op1 = xop1;
  2449.       converted = 1;
  2450.       resultcode = xresultcode;
  2451.  
  2452.       if (extra_warnings)
  2453.         {
  2454.           int op0_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op0));
  2455.           int op1_signed = ! TREE_UNSIGNED (TREE_TYPE (orig_op1));
  2456.  
  2457.           int unsignedp0, unsignedp1;
  2458.           tree primop0 = get_narrower (op0, &unsignedp0);
  2459.           tree primop1 = get_narrower (op1, &unsignedp1);
  2460.  
  2461.           /* Avoid spurious warnings for comparison with enumerators.  */
  2462.  
  2463.           xop0 = orig_op0;
  2464.           xop1 = orig_op1;
  2465.           STRIP_TYPE_NOPS (xop0);
  2466.           STRIP_TYPE_NOPS (xop1);
  2467.  
  2468.           /* Give warnings for comparisons between signed and unsigned
  2469.          quantities that may fail.  */
  2470.           /* Do the checking based on the original operand trees, so that
  2471.          casts will be considered, but default promotions won't be.  */
  2472.  
  2473.           /* Do not warn if the comparison is being done in a signed type,
  2474.          since the signed type will only be chosen if it can represent
  2475.          all the values of the unsigned type.  */
  2476.           if (! TREE_UNSIGNED (result_type))
  2477.         /* OK */;
  2478.               /* Do not warn if both operands are unsigned.  */
  2479.               else if (op0_signed == op1_signed)
  2480.                 /* OK */;
  2481.           /* Do not warn if the signed quantity is an unsuffixed
  2482.          integer literal (or some static constant expression
  2483.          involving such literals) and it is non-negative.  */
  2484.           else if ((op0_signed && TREE_CODE (xop0) == INTEGER_CST
  2485.             && tree_int_cst_sgn (xop0) >= 0)
  2486.                || (op1_signed && TREE_CODE (xop1) == INTEGER_CST
  2487.                && tree_int_cst_sgn (xop1) >= 0))
  2488.         /* OK */;
  2489.           /* Do not warn if the comparison is an equality operation,
  2490.                  the unsigned quantity is an integral constant and it does
  2491.                  not use the most significant bit of result_type.  */
  2492.           else if ((resultcode == EQ_EXPR || resultcode == NE_EXPR)
  2493.                && ((op0_signed && TREE_CODE (xop1) == INTEGER_CST
  2494.                 && int_fits_type_p (xop1, signed_type (result_type))
  2495.                || (op1_signed && TREE_CODE (xop0) == INTEGER_CST
  2496.                    && int_fits_type_p (xop0, signed_type (result_type))))))
  2497.         /* OK */;
  2498.           else
  2499.         warning ("comparison between signed and unsigned");
  2500.  
  2501.           /* Warn if two unsigned values are being compared in a size
  2502.          larger than their original size, and one (and only one) is the
  2503.          result of a `~' operator.  This comparison will always fail.
  2504.  
  2505.          Also warn if one operand is a constant, and the constant
  2506.          does not have all bits set that are set in the ~ operand
  2507.          when it is extended.  */
  2508.  
  2509.           if ((TREE_CODE (primop0) == BIT_NOT_EXPR)
  2510.           != (TREE_CODE (primop1) == BIT_NOT_EXPR))
  2511.         {
  2512.           if (TREE_CODE (primop0) == BIT_NOT_EXPR)
  2513.             primop0 = get_narrower (TREE_OPERAND (primop0, 0),
  2514.                         &unsignedp0);
  2515.           else
  2516.             primop1 = get_narrower (TREE_OPERAND (primop1, 0),
  2517.                         &unsignedp1);
  2518.           
  2519.           if (TREE_CODE (primop0) == INTEGER_CST
  2520.               || TREE_CODE (primop1) == INTEGER_CST)
  2521.             {
  2522.               tree primop;
  2523.               long constant, mask;
  2524.               int unsignedp, bits;
  2525.  
  2526.               if (TREE_CODE (primop0) == INTEGER_CST)
  2527.             {
  2528.               primop = primop1;
  2529.               unsignedp = unsignedp1;
  2530.               constant = TREE_INT_CST_LOW (primop0);
  2531.             }
  2532.               else
  2533.             {
  2534.               primop = primop0;
  2535.               unsignedp = unsignedp0;
  2536.               constant = TREE_INT_CST_LOW (primop1);
  2537.             }
  2538.  
  2539.               bits = TYPE_PRECISION (TREE_TYPE (primop));
  2540.               if (bits < TYPE_PRECISION (result_type)
  2541.               && bits < HOST_BITS_PER_LONG && unsignedp)
  2542.             {
  2543.               mask = (~0L) << bits;
  2544.               if ((mask & constant) != mask)
  2545.                 warning ("comparison of promoted ~unsigned with constant");
  2546.             }
  2547.             }
  2548.           else if (unsignedp0 && unsignedp1
  2549.                && (TYPE_PRECISION (TREE_TYPE (primop0))
  2550.                    < TYPE_PRECISION (result_type))
  2551.                && (TYPE_PRECISION (TREE_TYPE (primop1))
  2552.                    < TYPE_PRECISION (result_type)))
  2553.             warning ("comparison of promoted ~unsigned with unsigned");
  2554.         }
  2555.         }
  2556.     }
  2557.     }
  2558.  
  2559.   /* At this point, RESULT_TYPE must be nonzero to avoid an error message.
  2560.      If CONVERTED is zero, both args will be converted to type RESULT_TYPE.
  2561.      Then the expression will be built.
  2562.      It will be given type FINAL_TYPE if that is nonzero;
  2563.      otherwise, it will be given type RESULT_TYPE.  */
  2564.  
  2565.   if (!result_type)
  2566.     {
  2567.       binary_op_error (code);
  2568.       return error_mark_node;
  2569.     }
  2570.  
  2571.   if (! converted)
  2572.     {
  2573.       if (TREE_TYPE (op0) != result_type)
  2574.     op0 = convert (result_type, op0); 
  2575.       if (TREE_TYPE (op1) != result_type)
  2576.     op1 = convert (result_type, op1); 
  2577.     }
  2578.  
  2579.   if (build_type == NULL_TREE)
  2580.     build_type = result_type;
  2581.  
  2582.   {
  2583.     register tree result = build (resultcode, build_type, op0, op1);
  2584.     register tree folded;
  2585.  
  2586.     folded = fold (result);
  2587.     if (folded == result)
  2588.       TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  2589.     if (final_type != 0)
  2590.       return convert (final_type, folded);
  2591.     return folded;
  2592.   }
  2593. }
  2594.  
  2595. /* Return a tree for the sum or difference (RESULTCODE says which)
  2596.    of pointer PTROP and integer INTOP.  */
  2597.  
  2598. static tree
  2599. pointer_int_sum (resultcode, ptrop, intop)
  2600.      enum tree_code resultcode;
  2601.      register tree ptrop, intop;
  2602. {
  2603.   tree size_exp;
  2604.  
  2605.   register tree result;
  2606.   register tree folded;
  2607.  
  2608.   /* The result is a pointer of the same type that is being added.  */
  2609.  
  2610.   register tree result_type = TREE_TYPE (ptrop);
  2611.  
  2612.   if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
  2613.     {
  2614.       if (pedantic || warn_pointer_arith)
  2615.     pedwarn ("pointer of type `void *' used in arithmetic");
  2616.       size_exp = integer_one_node;
  2617.     }
  2618.   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
  2619.     {
  2620.       if (pedantic || warn_pointer_arith)
  2621.     pedwarn ("pointer to a function used in arithmetic");
  2622.       size_exp = integer_one_node;
  2623.     }
  2624.   else
  2625.     size_exp = c_size_in_bytes (TREE_TYPE (result_type));
  2626.  
  2627.   /* If what we are about to multiply by the size of the elements
  2628.      contains a constant term, apply distributive law
  2629.      and multiply that constant term separately.
  2630.      This helps produce common subexpressions.  */
  2631.  
  2632.   if ((TREE_CODE (intop) == PLUS_EXPR || TREE_CODE (intop) == MINUS_EXPR)
  2633.       && ! TREE_CONSTANT (intop)
  2634.       && TREE_CONSTANT (TREE_OPERAND (intop, 1))
  2635.       && TREE_CONSTANT (size_exp)
  2636.       /* If the constant comes from pointer subtraction,
  2637.      skip this optimization--it would cause an error.  */
  2638.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (intop, 0))) == INTEGER_TYPE)
  2639.     {
  2640.       enum tree_code subcode = resultcode;
  2641.       tree int_type = TREE_TYPE (intop);
  2642.       if (TREE_CODE (intop) == MINUS_EXPR)
  2643.     subcode = (subcode == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
  2644.       /* Convert both subexpression types to the type of intop,
  2645.      because weird cases involving pointer arithmetic
  2646.      can result in a sum or difference with different type args.  */
  2647.       ptrop = build_binary_op (subcode, ptrop,
  2648.                    convert (int_type, TREE_OPERAND (intop, 1)), 1);
  2649.       intop = convert (int_type, TREE_OPERAND (intop, 0));
  2650.     }
  2651.  
  2652.   /* Convert the integer argument to a type the same size as a pointer
  2653.      so the multiply won't overflow spuriously.  */
  2654.  
  2655.   if (TYPE_PRECISION (TREE_TYPE (intop)) != POINTER_SIZE)
  2656.     intop = convert (type_for_size (POINTER_SIZE, 0), intop);
  2657.  
  2658.   /* Replace the integer argument with a suitable product by the object size.
  2659.      Do this multiplication as signed, then convert to the appropriate
  2660.      pointer type (actually unsigned integral).  */
  2661.  
  2662.   intop = convert (result_type,
  2663.            build_binary_op (MULT_EXPR, intop,
  2664.                     convert (TREE_TYPE (intop), size_exp), 1));
  2665.  
  2666.   /* Create the sum or difference.  */
  2667.  
  2668.   result = build (resultcode, result_type, ptrop, intop);
  2669.  
  2670.   folded = fold (result);
  2671.   if (folded == result)
  2672.     TREE_CONSTANT (folded) = TREE_CONSTANT (ptrop) & TREE_CONSTANT (intop);
  2673.   return folded;
  2674. }
  2675.  
  2676. /* Return a tree for the difference of pointers OP0 and OP1.
  2677.    The resulting tree has type int.  */
  2678.  
  2679. static tree
  2680. pointer_diff (op0, op1)
  2681.      register tree op0, op1;
  2682. {
  2683.   register tree result, folded;
  2684.   tree restype = ptrdiff_type_node;
  2685.  
  2686.   tree target_type = TREE_TYPE (TREE_TYPE (op0));
  2687.  
  2688.   if (pedantic || warn_pointer_arith)
  2689.     {
  2690.       if (TREE_CODE (target_type) == VOID_TYPE)
  2691.     pedwarn ("pointer of type `void *' used in subtraction");
  2692.       if (TREE_CODE (target_type) == FUNCTION_TYPE)
  2693.     pedwarn ("pointer to a function used in subtraction");
  2694.     }
  2695.  
  2696.   /* First do the subtraction as integers;
  2697.      then drop through to build the divide operator.  */
  2698.  
  2699.   op0 = build_binary_op (MINUS_EXPR, convert (restype, op0),
  2700.              convert (restype, op1), 1);
  2701.   /* This generates an error if op1 is pointer to incomplete type.  */
  2702.   if (TYPE_SIZE (TREE_TYPE (TREE_TYPE (op1))) == 0)
  2703.     error ("arithmetic on pointer to an incomplete type");
  2704.  
  2705.   /* This generates an error if op0 is pointer to incomplete type.  */
  2706.   op1 = c_size_in_bytes (target_type);
  2707.  
  2708.   /* Divide by the size, in easiest possible way.  */
  2709.  
  2710.   result = build (EXACT_DIV_EXPR, restype, op0, convert (restype, op1));
  2711.  
  2712.   folded = fold (result);
  2713.   if (folded == result)
  2714.     TREE_CONSTANT (folded) = TREE_CONSTANT (op0) & TREE_CONSTANT (op1);
  2715.   return folded;
  2716. }
  2717.  
  2718. /* Construct and perhaps optimize a tree representation
  2719.    for a unary operation.  CODE, a tree_code, specifies the operation
  2720.    and XARG is the operand.  NOCONVERT nonzero suppresses
  2721.    the default promotions (such as from short to int).  */
  2722.  
  2723. tree
  2724. build_unary_op (code, xarg, noconvert)
  2725.      enum tree_code code;
  2726.      tree xarg;
  2727.      int noconvert;
  2728. {
  2729.   /* No default_conversion here.  It causes trouble for ADDR_EXPR.  */
  2730.   register tree arg = xarg;
  2731.   register tree argtype = 0;
  2732.   register enum tree_code typecode = TREE_CODE (TREE_TYPE (arg));
  2733.   char *errstring = NULL;
  2734.   tree val;
  2735.  
  2736.   if (typecode == ERROR_MARK)
  2737.     return error_mark_node;
  2738.   if (typecode == ENUMERAL_TYPE)
  2739.     typecode = INTEGER_TYPE;
  2740.  
  2741.   switch (code)
  2742.     {
  2743.     case CONVERT_EXPR:
  2744.       /* This is used for unary plus, because a CONVERT_EXPR
  2745.      is enough to prevent anybody from looking inside for
  2746.      associativity, but won't generate any code.  */
  2747.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
  2748.         || typecode == COMPLEX_TYPE))
  2749.         errstring = "wrong type argument to unary plus";
  2750.       else if (!noconvert)
  2751.     arg = default_conversion (arg);
  2752.       break;
  2753.  
  2754.     case NEGATE_EXPR:
  2755.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
  2756.         || typecode == COMPLEX_TYPE))
  2757.         errstring = "wrong type argument to unary minus";
  2758.       else if (!noconvert)
  2759.     arg = default_conversion (arg);
  2760.       break;
  2761.  
  2762.     case BIT_NOT_EXPR:
  2763.       if (typecode == COMPLEX_TYPE)
  2764.     {
  2765.       code = CONJ_EXPR;
  2766.       if (!noconvert)
  2767.         arg = default_conversion (arg);
  2768.     }
  2769.       else if (typecode != INTEGER_TYPE)
  2770.         errstring = "wrong type argument to bit-complement";
  2771.       else if (!noconvert)
  2772.     arg = default_conversion (arg);
  2773.       break;
  2774.  
  2775.     case ABS_EXPR:
  2776.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
  2777.         || typecode == COMPLEX_TYPE))
  2778.         errstring = "wrong type argument to abs";
  2779.       else if (!noconvert)
  2780.     arg = default_conversion (arg);
  2781.       break;
  2782.  
  2783.     case CONJ_EXPR:
  2784.       /* Conjugating a real value is a no-op, but allow it anyway.  */
  2785.       if (!(typecode == INTEGER_TYPE || typecode == REAL_TYPE
  2786.         || typecode == COMPLEX_TYPE))
  2787.     errstring = "wrong type argument to conjugation";
  2788.       else if (!noconvert)
  2789.     arg = default_conversion (arg);
  2790.       break;
  2791.  
  2792.     case TRUTH_NOT_EXPR:
  2793.       if (typecode != INTEGER_TYPE
  2794.       && typecode != REAL_TYPE && typecode != POINTER_TYPE
  2795.       && typecode != COMPLEX_TYPE
  2796.       /* These will convert to a pointer.  */
  2797.       && typecode != ARRAY_TYPE && typecode != FUNCTION_TYPE)
  2798.     {
  2799.       errstring = "wrong type argument to unary exclamation mark";
  2800.       break;
  2801.     }
  2802.       arg = truthvalue_conversion (arg);
  2803.       return invert_truthvalue (arg);
  2804.  
  2805.     case NOP_EXPR:
  2806.       break;
  2807.  
  2808.     case REALPART_EXPR:
  2809.       if (TREE_CODE (arg) == COMPLEX_CST)
  2810.     return TREE_REALPART (arg);
  2811.       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
  2812.     return fold (build1 (REALPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
  2813.       else
  2814.     return arg;
  2815.  
  2816.     case IMAGPART_EXPR:
  2817.       if (TREE_CODE (arg) == COMPLEX_CST)
  2818.     return TREE_IMAGPART (arg);
  2819.       else if (TREE_CODE (TREE_TYPE (arg)) == COMPLEX_TYPE)
  2820.     return fold (build1 (IMAGPART_EXPR, TREE_TYPE (TREE_TYPE (arg)), arg));
  2821.       else
  2822.     return convert (TREE_TYPE (arg), integer_zero_node);
  2823.       
  2824.     case PREINCREMENT_EXPR:
  2825.     case POSTINCREMENT_EXPR:
  2826.     case PREDECREMENT_EXPR:
  2827.     case POSTDECREMENT_EXPR:
  2828.       /* Handle complex lvalues (when permitted)
  2829.      by reduction to simpler cases.  */
  2830.  
  2831.       val = unary_complex_lvalue (code, arg);
  2832.       if (val != 0)
  2833.     return val;
  2834.  
  2835.       /* Increment or decrement the real part of the value,
  2836.      and don't change the imaginary part.  */
  2837.       if (typecode == COMPLEX_TYPE)
  2838.     {
  2839.       tree real, imag;
  2840.  
  2841.       arg = stabilize_reference (arg);
  2842.       real = build_unary_op (REALPART_EXPR, arg, 1);
  2843.       imag = build_unary_op (IMAGPART_EXPR, arg, 1);
  2844.       return build (COMPLEX_EXPR, TREE_TYPE (arg),
  2845.             build_unary_op (code, real, 1), imag);
  2846.     }
  2847.  
  2848.       /* Report invalid types.  */
  2849.  
  2850.       if (typecode != POINTER_TYPE
  2851.       && typecode != INTEGER_TYPE && typecode != REAL_TYPE)
  2852.     {
  2853.       if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
  2854.         errstring ="wrong type argument to increment";
  2855.       else
  2856.         errstring ="wrong type argument to decrement";
  2857.       break;
  2858.     }
  2859.  
  2860.       {
  2861.     register tree inc;
  2862.     tree result_type = TREE_TYPE (arg);
  2863.  
  2864.     arg = get_unwidened (arg, 0);
  2865.     argtype = TREE_TYPE (arg);
  2866.  
  2867.     /* Compute the increment.  */
  2868.  
  2869.     if (typecode == POINTER_TYPE)
  2870.       {
  2871.         /* If pointer target is an undefined struct,
  2872.            we just cannot know how to do the arithmetic.  */
  2873.         if (TYPE_SIZE (TREE_TYPE (result_type)) == 0)
  2874.           error ("%s of pointer to unknown structure",
  2875.                ((code == PREINCREMENT_EXPR
  2876.              || code == POSTINCREMENT_EXPR)
  2877.             ? "increment" : "decrement"));
  2878.         else if ((pedantic || warn_pointer_arith)
  2879.              && (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE
  2880.              || TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE))
  2881.           pedwarn ("wrong type argument to %s",
  2882.                ((code == PREINCREMENT_EXPR
  2883.              || code == POSTINCREMENT_EXPR)
  2884.             ? "increment" : "decrement"));
  2885.         inc = c_size_in_bytes (TREE_TYPE (result_type));
  2886.       }
  2887.     else
  2888.       inc = integer_one_node;
  2889.  
  2890.     inc = convert (argtype, inc);
  2891.  
  2892.     /* Handle incrementing a cast-expression.  */
  2893.  
  2894.     while (1)
  2895.       switch (TREE_CODE (arg))
  2896.         {
  2897.         case NOP_EXPR:
  2898.         case CONVERT_EXPR:
  2899.         case FLOAT_EXPR:
  2900.         case FIX_TRUNC_EXPR:
  2901.         case FIX_FLOOR_EXPR:
  2902.         case FIX_ROUND_EXPR:
  2903.         case FIX_CEIL_EXPR:
  2904.           pedantic_lvalue_warning (CONVERT_EXPR);
  2905.           /* If the real type has the same machine representation
  2906.          as the type it is cast to, we can make better output
  2907.          by adding directly to the inside of the cast.  */
  2908.           if ((TREE_CODE (TREE_TYPE (arg))
  2909.            == TREE_CODE (TREE_TYPE (TREE_OPERAND (arg, 0))))
  2910.           && (TYPE_MODE (TREE_TYPE (arg))
  2911.               == TYPE_MODE (TREE_TYPE (TREE_OPERAND (arg, 0)))))
  2912.         arg = TREE_OPERAND (arg, 0);
  2913.           else
  2914.         {
  2915.           tree incremented, modify, value;
  2916.           arg = stabilize_reference (arg);
  2917.           if (code == PREINCREMENT_EXPR || code == PREDECREMENT_EXPR)
  2918.             value = arg;
  2919.           else
  2920.             value = save_expr (arg);
  2921.           incremented = build (((code == PREINCREMENT_EXPR
  2922.                      || code == POSTINCREMENT_EXPR)
  2923.                     ? PLUS_EXPR : MINUS_EXPR),
  2924.                        argtype, value, inc);
  2925.           TREE_SIDE_EFFECTS (incremented) = 1;
  2926.           modify = build_modify_expr (arg, NOP_EXPR, incremented);
  2927.           value = build (COMPOUND_EXPR, TREE_TYPE (arg), modify, value);
  2928.           TREE_USED (value) = 1;
  2929.           return value;
  2930.         }
  2931.           break;
  2932.  
  2933.         default:
  2934.           goto give_up;
  2935.         }
  2936.       give_up:
  2937.  
  2938.     /* Complain about anything else that is not a true lvalue.  */
  2939.     if (!lvalue_or_else (arg, ((code == PREINCREMENT_EXPR
  2940.                     || code == POSTINCREMENT_EXPR)
  2941.                    ? "increment" : "decrement")))
  2942.       return error_mark_node;
  2943.  
  2944.     /* Report a read-only lvalue.  */
  2945.     if (TREE_READONLY (arg))
  2946.       readonly_warning (arg, 
  2947.                 ((code == PREINCREMENT_EXPR
  2948.                   || code == POSTINCREMENT_EXPR)
  2949.                  ? "increment" : "decrement"));
  2950.  
  2951.     val = build (code, TREE_TYPE (arg), arg, inc);
  2952.     TREE_SIDE_EFFECTS (val) = 1;
  2953.     val = convert (result_type, val);
  2954.     if (TREE_CODE (val) != code)
  2955.       TREE_NO_UNUSED_WARNING (val) = 1;
  2956.     return val;
  2957.       }
  2958.  
  2959.     case ADDR_EXPR:
  2960.       /* Note that this operation never does default_conversion
  2961.      regardless of NOCONVERT.  */
  2962.  
  2963.       /* Let &* cancel out to simplify resulting code.  */
  2964.       if (TREE_CODE (arg) == INDIRECT_REF)
  2965.     {
  2966.       /* Don't let this be an lvalue.  */
  2967.       if (lvalue_p (TREE_OPERAND (arg, 0)))
  2968.         return non_lvalue (TREE_OPERAND (arg, 0));
  2969.       return TREE_OPERAND (arg, 0);
  2970.     }
  2971.  
  2972.       /* For &x[y], return x+y */
  2973.       if (TREE_CODE (arg) == ARRAY_REF)
  2974.     {
  2975.       if (mark_addressable (TREE_OPERAND (arg, 0)) == 0)
  2976.         return error_mark_node;
  2977.       return build_binary_op (PLUS_EXPR, TREE_OPERAND (arg, 0),
  2978.                   TREE_OPERAND (arg, 1), 1);
  2979.     }
  2980.  
  2981.       /* Handle complex lvalues (when permitted)
  2982.      by reduction to simpler cases.  */
  2983.       val = unary_complex_lvalue (code, arg);
  2984.       if (val != 0)
  2985.     return val;
  2986.  
  2987. #if 0 /* Turned off because inconsistent;
  2988.      float f; *&(int)f = 3.4 stores in int format
  2989.      whereas (int)f = 3.4 stores in float format.  */
  2990.       /* Address of a cast is just a cast of the address
  2991.      of the operand of the cast.  */
  2992.       switch (TREE_CODE (arg))
  2993.     {
  2994.     case NOP_EXPR:
  2995.     case CONVERT_EXPR:
  2996.     case FLOAT_EXPR:
  2997.     case FIX_TRUNC_EXPR:
  2998.     case FIX_FLOOR_EXPR:
  2999.     case FIX_ROUND_EXPR:
  3000.     case FIX_CEIL_EXPR:
  3001.       if (pedantic)
  3002.         pedwarn ("ANSI C forbids the address of a cast expression");
  3003.       return convert (build_pointer_type (TREE_TYPE (arg)),
  3004.               build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0),
  3005.                       0));
  3006.     }
  3007. #endif
  3008.  
  3009.       /* Allow the address of a constructor if all the elements
  3010.      are constant.  */
  3011.       if (TREE_CODE (arg) == CONSTRUCTOR && TREE_CONSTANT (arg))
  3012.     ;
  3013.       /* Anything not already handled and not a true memory reference
  3014.      is an error.  */
  3015.       else if (typecode != FUNCTION_TYPE && !lvalue_or_else (arg, "unary `&'"))
  3016.     return error_mark_node;
  3017.  
  3018.       /* Ordinary case; arg is a COMPONENT_REF or a decl.  */
  3019.       argtype = TREE_TYPE (arg);
  3020.       /* If the lvalue is const or volatile,
  3021.      merge that into the type that the address will point to.  */
  3022.       if (TREE_CODE_CLASS (TREE_CODE (arg)) == 'd'
  3023.       || TREE_CODE_CLASS (TREE_CODE (arg)) == 'r')
  3024.     {
  3025.       if (TREE_READONLY (arg) || TREE_THIS_VOLATILE (arg))
  3026.         argtype = c_build_type_variant (argtype,
  3027.                         TREE_READONLY (arg),
  3028.                         TREE_THIS_VOLATILE (arg));
  3029.     }
  3030.  
  3031.       argtype = build_pointer_type (argtype);
  3032.  
  3033.       if (mark_addressable (arg) == 0)
  3034.     return error_mark_node;
  3035.  
  3036.       {
  3037.     tree addr;
  3038.  
  3039.     if (TREE_CODE (arg) == COMPONENT_REF)
  3040.       {
  3041.         tree field = TREE_OPERAND (arg, 1);
  3042.  
  3043.         addr = build_unary_op (ADDR_EXPR, TREE_OPERAND (arg, 0), 0);
  3044.  
  3045.         if (DECL_BIT_FIELD (field))
  3046.           {
  3047.         error ("attempt to take address of bit-field structure member `%s'",
  3048.                IDENTIFIER_POINTER (DECL_NAME (field)));
  3049.         return error_mark_node;
  3050.           }
  3051.  
  3052.         addr = convert (argtype, addr);
  3053.  
  3054.         if (! integer_zerop (DECL_FIELD_BITPOS (field)))
  3055.           {
  3056.         tree offset
  3057.           = size_binop (EASY_DIV_EXPR, DECL_FIELD_BITPOS (field),
  3058.                 size_int (BITS_PER_UNIT));
  3059.         int flag = TREE_CONSTANT (addr);
  3060.         addr = fold (build (PLUS_EXPR, argtype,
  3061.                     addr, convert (argtype, offset)));
  3062.         TREE_CONSTANT (addr) = flag;
  3063.           }
  3064.       }
  3065.     else
  3066.       addr = build1 (code, argtype, arg);
  3067.  
  3068.     /* Address of a static or external variable or
  3069.        file-scope function counts as a constant.  */
  3070.     if (staticp (arg)
  3071.         && ! (TREE_CODE (arg) == FUNCTION_DECL
  3072.           && DECL_CONTEXT (arg) != 0))
  3073.       TREE_CONSTANT (addr) = 1;
  3074.     return addr;
  3075.       }
  3076.     }
  3077.  
  3078.   if (!errstring)
  3079.     {
  3080.       if (argtype == 0)
  3081.     argtype = TREE_TYPE (arg);
  3082.       return fold (build1 (code, argtype, arg));
  3083.     }
  3084.  
  3085.   error (errstring);
  3086.   return error_mark_node;
  3087. }
  3088.  
  3089. #if 0
  3090. /* If CONVERSIONS is a conversion expression or a nested sequence of such,
  3091.    convert ARG with the same conversions in the same order
  3092.    and return the result.  */
  3093.  
  3094. static tree
  3095. convert_sequence (conversions, arg)
  3096.      tree conversions;
  3097.      tree arg;
  3098. {
  3099.   switch (TREE_CODE (conversions))
  3100.     {
  3101.     case NOP_EXPR:
  3102.     case CONVERT_EXPR:
  3103.     case FLOAT_EXPR:
  3104.     case FIX_TRUNC_EXPR:
  3105.     case FIX_FLOOR_EXPR:
  3106.     case FIX_ROUND_EXPR:
  3107.     case FIX_CEIL_EXPR:
  3108.       return convert (TREE_TYPE (conversions),
  3109.               convert_sequence (TREE_OPERAND (conversions, 0),
  3110.                     arg));
  3111.  
  3112.     default:
  3113.       return arg;
  3114.     }
  3115. }
  3116. #endif /* 0 */
  3117.  
  3118. /* Return nonzero if REF is an lvalue valid for this language.
  3119.    Lvalues can be assigned, unless their type has TYPE_READONLY.
  3120.    Lvalues can have their address taken, unless they have DECL_REGISTER.  */
  3121.  
  3122. int
  3123. lvalue_p (ref)
  3124.      tree ref;
  3125. {
  3126.   register enum tree_code code = TREE_CODE (ref);
  3127.  
  3128.   switch (code)
  3129.     {
  3130.     case REALPART_EXPR:
  3131.     case IMAGPART_EXPR:
  3132.     case COMPONENT_REF:
  3133.       return lvalue_p (TREE_OPERAND (ref, 0));
  3134.  
  3135.     case STRING_CST:
  3136.       return 1;
  3137.  
  3138.     case INDIRECT_REF:
  3139.     case ARRAY_REF:
  3140.     case VAR_DECL:
  3141.     case PARM_DECL:
  3142.     case RESULT_DECL:
  3143.     case ERROR_MARK:
  3144.       if (TREE_CODE (TREE_TYPE (ref)) != FUNCTION_TYPE
  3145.       && TREE_CODE (TREE_TYPE (ref)) != METHOD_TYPE)
  3146.     return 1;
  3147.       break;
  3148.     }
  3149.   return 0;
  3150. }
  3151.  
  3152. /* Return nonzero if REF is an lvalue valid for this language;
  3153.    otherwise, print an error message and return zero.  */
  3154.  
  3155. int
  3156. lvalue_or_else (ref, string)
  3157.      tree ref;
  3158.      char *string;
  3159. {
  3160.   int win = lvalue_p (ref);
  3161.   if (! win)
  3162.     error ("invalid lvalue in %s", string);
  3163.   return win;
  3164. }
  3165.  
  3166. /* Apply unary lvalue-demanding operator CODE to the expression ARG
  3167.    for certain kinds of expressions which are not really lvalues
  3168.    but which we can accept as lvalues.
  3169.  
  3170.    If ARG is not a kind of expression we can handle, return zero.  */
  3171.    
  3172. static tree
  3173. unary_complex_lvalue (code, arg)
  3174.      enum tree_code code;
  3175.      tree arg;
  3176. {
  3177.   /* Handle (a, b) used as an "lvalue".  */
  3178.   if (TREE_CODE (arg) == COMPOUND_EXPR)
  3179.     {
  3180.       tree real_result = build_unary_op (code, TREE_OPERAND (arg, 1), 0);
  3181.       pedantic_lvalue_warning (COMPOUND_EXPR);
  3182.       return build (COMPOUND_EXPR, TREE_TYPE (real_result),
  3183.             TREE_OPERAND (arg, 0), real_result);
  3184.     }
  3185.  
  3186.   /* Handle (a ? b : c) used as an "lvalue".  */
  3187.   if (TREE_CODE (arg) == COND_EXPR)
  3188.     {
  3189.       pedantic_lvalue_warning (COND_EXPR);
  3190.       return (build_conditional_expr
  3191.           (TREE_OPERAND (arg, 0),
  3192.            build_unary_op (code, TREE_OPERAND (arg, 1), 0),
  3193.            build_unary_op (code, TREE_OPERAND (arg, 2), 0)));
  3194.     }
  3195.  
  3196.   return 0;
  3197. }
  3198.  
  3199. /* If pedantic, warn about improper lvalue.   CODE is either COND_EXPR
  3200.    COMPOUND_EXPR, or CONVERT_EXPR (for casts).  */
  3201.  
  3202. static void
  3203. pedantic_lvalue_warning (code)
  3204.      enum tree_code code;
  3205. {
  3206.   if (pedantic)
  3207.     pedwarn ("ANSI C forbids use of %s expressions as lvalues",
  3208.          code == COND_EXPR ? "conditional"
  3209.          : code == COMPOUND_EXPR ? "compound" : "cast");
  3210. }
  3211.  
  3212. /* Warn about storing in something that is `const'.  */
  3213.  
  3214. void
  3215. readonly_warning (arg, string)
  3216.      tree arg;
  3217.      char *string;
  3218. {
  3219.   char buf[80];
  3220.   strcpy (buf, string);
  3221.  
  3222.   /* Forbid assignments to iterators.  */
  3223.   if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg))
  3224.     {
  3225.       strcat (buf, " of iterator `%s'");
  3226.       pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
  3227.     }
  3228.  
  3229.   if (TREE_CODE (arg) == COMPONENT_REF)
  3230.     {
  3231.       if (TYPE_READONLY (TREE_TYPE (TREE_OPERAND (arg, 0))))
  3232.     readonly_warning (TREE_OPERAND (arg, 0), string);
  3233.       else
  3234.     {
  3235.       strcat (buf, " of read-only member `%s'");
  3236.       pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (TREE_OPERAND (arg, 1))));
  3237.     }
  3238.     }
  3239.   else if (TREE_CODE (arg) == VAR_DECL)
  3240.     {
  3241.       strcat (buf, " of read-only variable `%s'");
  3242.       pedwarn (buf, IDENTIFIER_POINTER (DECL_NAME (arg)));
  3243.     }
  3244.   else
  3245.     {
  3246.       pedwarn ("%s of read-only location", buf);
  3247.     }
  3248. }
  3249.  
  3250. /* Mark EXP saying that we need to be able to take the
  3251.    address of it; it should not be allocated in a register.
  3252.    Value is 1 if successful.  */
  3253.  
  3254. int
  3255. mark_addressable (exp)
  3256.      tree exp;
  3257. {
  3258.   register tree x = exp;
  3259.   while (1)
  3260.     switch (TREE_CODE (x))
  3261.       {
  3262.       case ADDR_EXPR:
  3263.       case COMPONENT_REF:
  3264.       case ARRAY_REF:
  3265.       case REALPART_EXPR:
  3266.       case IMAGPART_EXPR:
  3267.     x = TREE_OPERAND (x, 0);
  3268.     break;
  3269.  
  3270.       case CONSTRUCTOR:
  3271.     TREE_ADDRESSABLE (x) = 1;
  3272.     return 1;
  3273.  
  3274.       case VAR_DECL:
  3275.       case CONST_DECL:
  3276.       case PARM_DECL:
  3277.       case RESULT_DECL:
  3278.     if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x)
  3279.         && DECL_NONLOCAL (x))
  3280.       {
  3281.         if (TREE_PUBLIC (x))
  3282.           {
  3283.         error ("global register variable `%s' used in nested function",
  3284.                IDENTIFIER_POINTER (DECL_NAME (x)));
  3285.         return 0;
  3286.           }
  3287.         pedwarn ("register variable `%s' used in nested function",
  3288.              IDENTIFIER_POINTER (DECL_NAME (x)));
  3289.       }
  3290.     else if (DECL_REGISTER (x) && !TREE_ADDRESSABLE (x))
  3291.       {
  3292.         if (TREE_PUBLIC (x))
  3293.           {
  3294.         error ("address of global register variable `%s' requested",
  3295.                IDENTIFIER_POINTER (DECL_NAME (x)));
  3296.         return 0;
  3297.           }
  3298.  
  3299.         /* If we are making this addressable due to its having
  3300.            volatile components, give a different error message.  Also
  3301.            handle the case of an unnamed parameter by not trying
  3302.            to give the name.  */
  3303.  
  3304.         else if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (x)))
  3305.           {
  3306.         error ("cannot put object with volatile field into register");
  3307.         return 0;
  3308.           }
  3309.  
  3310.         pedwarn ("address of register variable `%s' requested",
  3311.              IDENTIFIER_POINTER (DECL_NAME (x)));
  3312.       }
  3313.     put_var_into_stack (x);
  3314.  
  3315.     /* drops in */
  3316.       case FUNCTION_DECL:
  3317.     TREE_ADDRESSABLE (x) = 1;
  3318. #if 0  /* poplevel deals with this now.  */
  3319.     if (DECL_CONTEXT (x) == 0)
  3320.       TREE_ADDRESSABLE (DECL_ASSEMBLER_NAME (x)) = 1;
  3321. #endif
  3322.  
  3323.       default:
  3324.     return 1;
  3325.     }
  3326. }
  3327.  
  3328. /* Build and return a conditional expression IFEXP ? OP1 : OP2.  */
  3329.  
  3330. tree
  3331. build_conditional_expr (ifexp, op1, op2)
  3332.      tree ifexp, op1, op2;
  3333. {
  3334.   register tree type1;
  3335.   register tree type2;
  3336.   register enum tree_code code1;
  3337.   register enum tree_code code2;
  3338.   register tree result_type = NULL;
  3339.   tree orig_op1 = op1, orig_op2 = op2;
  3340.  
  3341.   /* If second operand is omitted, it is the same as the first one;
  3342.      make sure it is calculated only once.  */
  3343.   if (op1 == 0)
  3344.     {
  3345.       if (pedantic)
  3346.     pedwarn ("ANSI C forbids omitting the middle term of a ?: expression");
  3347.       ifexp = op1 = save_expr (ifexp);
  3348.     }
  3349.  
  3350.   ifexp = truthvalue_conversion (default_conversion (ifexp));
  3351.  
  3352. #if 0 /* Produces wrong result if within sizeof.  */
  3353.   /* Don't promote the operands separately if they promote
  3354.      the same way.  Return the unpromoted type and let the combined
  3355.      value get promoted if necessary.  */
  3356.  
  3357.   if (TREE_TYPE (op1) == TREE_TYPE (op2)
  3358.       && TREE_CODE (TREE_TYPE (op1)) != ARRAY_TYPE
  3359.       && TREE_CODE (TREE_TYPE (op1)) != ENUMERAL_TYPE
  3360.       && TREE_CODE (TREE_TYPE (op1)) != FUNCTION_TYPE)
  3361.     {
  3362.       if (TREE_CODE (ifexp) == INTEGER_CST)
  3363.     return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
  3364.  
  3365.       return fold (build (COND_EXPR, TREE_TYPE (op1), ifexp, op1, op2));
  3366.     }
  3367. #endif
  3368.  
  3369.   /* Promote both alternatives.  */
  3370.  
  3371.   if (TREE_CODE (TREE_TYPE (op1)) != VOID_TYPE)
  3372.     op1 = default_conversion (op1);
  3373.   if (TREE_CODE (TREE_TYPE (op2)) != VOID_TYPE)
  3374.     op2 = default_conversion (op2);
  3375.  
  3376.   if (TREE_CODE (ifexp) == ERROR_MARK
  3377.       || TREE_CODE (TREE_TYPE (op1)) == ERROR_MARK
  3378.       || TREE_CODE (TREE_TYPE (op2)) == ERROR_MARK)
  3379.     return error_mark_node;
  3380.  
  3381.   type1 = TREE_TYPE (op1);
  3382.   code1 = TREE_CODE (type1);
  3383.   type2 = TREE_TYPE (op2);
  3384.   code2 = TREE_CODE (type2);
  3385.       
  3386.   /* Quickly detect the usual case where op1 and op2 have the same type
  3387.      after promotion.  */
  3388.   if (TYPE_MAIN_VARIANT (type1) == TYPE_MAIN_VARIANT (type2))
  3389.     {
  3390.       if (type1 == type2)
  3391.     result_type = type1;
  3392.       else
  3393.     result_type = TYPE_MAIN_VARIANT (type1);
  3394.     }
  3395.   else if ((code1 == INTEGER_TYPE || code1 == REAL_TYPE)
  3396.            && (code2 == INTEGER_TYPE || code2 == REAL_TYPE))
  3397.     {
  3398.       result_type = common_type (type1, type2);
  3399.     }
  3400.   else if (code1 == VOID_TYPE || code2 == VOID_TYPE)
  3401.     {
  3402.       if (pedantic && (code1 != VOID_TYPE || code2 != VOID_TYPE))
  3403.     pedwarn ("ANSI C forbids conditional expr with only one void side");
  3404.       result_type = void_type_node;
  3405.     }
  3406.   else if (code1 == POINTER_TYPE && code2 == POINTER_TYPE)
  3407.     {
  3408.       if (comp_target_types (type1, type2))
  3409.     result_type = common_type (type1, type2);
  3410.       else if (integer_zerop (op1) && TREE_TYPE (type1) == void_type_node
  3411.            && TREE_CODE (orig_op1) != NOP_EXPR)
  3412.     result_type = qualify_type (type2, type1);
  3413.       else if (integer_zerop (op2) && TREE_TYPE (type2) == void_type_node
  3414.            && TREE_CODE (orig_op2) != NOP_EXPR)
  3415.     result_type = qualify_type (type1, type2);
  3416.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type1)) == void_type_node)
  3417.     {
  3418.       if (pedantic && TREE_CODE (TREE_TYPE (type2)) == FUNCTION_TYPE)
  3419.         pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
  3420.       result_type = qualify_type (type1, type2);
  3421.     }
  3422.       else if (TYPE_MAIN_VARIANT (TREE_TYPE (type2)) == void_type_node)
  3423.     {
  3424.       if (pedantic && TREE_CODE (TREE_TYPE (type1)) == FUNCTION_TYPE)
  3425.         pedwarn ("ANSI C forbids conditional expr between `void *' and function pointer");
  3426.       result_type = qualify_type (type2, type1);
  3427.     }
  3428.       else
  3429.     {
  3430.       pedwarn ("pointer type mismatch in conditional expression");
  3431.       result_type = build_pointer_type (void_type_node);
  3432.     }
  3433.     }
  3434.   else if (code1 == POINTER_TYPE && code2 == INTEGER_TYPE)
  3435.     {
  3436.       if (! integer_zerop (op2))
  3437.     pedwarn ("pointer/integer type mismatch in conditional expression");
  3438.       else
  3439.     {
  3440.       op2 = null_pointer_node;
  3441. #if 0  /* The spec seems to say this is permitted.  */
  3442.       if (pedantic && TREE_CODE (type1) == FUNCTION_TYPE)
  3443.         pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
  3444. #endif
  3445.     }
  3446.       result_type = type1;
  3447.     }
  3448.   else if (code2 == POINTER_TYPE && code1 == INTEGER_TYPE)
  3449.     {
  3450.       if (!integer_zerop (op1))
  3451.     pedwarn ("pointer/integer type mismatch in conditional expression");
  3452.       else
  3453.     {
  3454.       op1 = null_pointer_node;
  3455. #if 0  /* The spec seems to say this is permitted.  */
  3456.       if (pedantic && TREE_CODE (type2) == FUNCTION_TYPE)
  3457.         pedwarn ("ANSI C forbids conditional expr between 0 and function pointer");
  3458. #endif
  3459.     }
  3460.       result_type = type2;
  3461.     }
  3462.  
  3463.   if (!result_type)
  3464.     {
  3465.       if (flag_cond_mismatch)
  3466.     result_type = void_type_node;
  3467.       else
  3468.     {
  3469.       error ("type mismatch in conditional expression");
  3470.       return error_mark_node;
  3471.     }
  3472.     }
  3473.  
  3474.   /* Merge const and volatile flags of the incoming types.  */
  3475.   result_type
  3476.     = build_type_variant (result_type,
  3477.               TREE_READONLY (op1) || TREE_READONLY (op2),
  3478.               TREE_THIS_VOLATILE (op1) || TREE_THIS_VOLATILE (op2));
  3479.  
  3480.   if (result_type != TREE_TYPE (op1))
  3481.     op1 = convert_and_check (result_type, op1);
  3482.   if (result_type != TREE_TYPE (op2))
  3483.     op2 = convert_and_check (result_type, op2);
  3484.     
  3485. #if 0
  3486.   if (code1 == RECORD_TYPE || code1 == UNION_TYPE)
  3487.     {
  3488.       result_type = TREE_TYPE (op1);
  3489.       if (TREE_CONSTANT (ifexp))
  3490.     return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
  3491.  
  3492.       if (TYPE_MODE (result_type) == BLKmode)
  3493.     {
  3494.       register tree tempvar
  3495.         = build_decl (VAR_DECL, NULL_TREE, result_type);
  3496.       register tree xop1 = build_modify_expr (tempvar, op1);
  3497.       register tree xop2 = build_modify_expr (tempvar, op2);
  3498.       register tree result = fold (build (COND_EXPR, result_type,
  3499.                           ifexp, xop1, xop2));
  3500.  
  3501.       layout_decl (tempvar, TYPE_ALIGN (result_type));
  3502.       /* No way to handle variable-sized objects here.
  3503.          I fear that the entire handling of BLKmode conditional exprs
  3504.          needs to be redone.  */
  3505.       if (TREE_CODE (DECL_SIZE (tempvar)) != INTEGER_CST)
  3506.         abort ();
  3507.       DECL_RTL (tempvar)
  3508.         = assign_stack_local (DECL_MODE (tempvar),
  3509.                   (TREE_INT_CST_LOW (DECL_SIZE (tempvar))
  3510.                    + BITS_PER_UNIT - 1)
  3511.                   / BITS_PER_UNIT,
  3512.                   0);
  3513.  
  3514.       TREE_SIDE_EFFECTS (result)
  3515.         = TREE_SIDE_EFFECTS (ifexp) | TREE_SIDE_EFFECTS (op1)
  3516.           | TREE_SIDE_EFFECTS (op2);
  3517.       return build (COMPOUND_EXPR, result_type, result, tempvar);
  3518.     }
  3519.     }
  3520. #endif /* 0 */
  3521.     
  3522.   if (TREE_CODE (ifexp) == INTEGER_CST)
  3523.     return pedantic_non_lvalue (integer_zerop (ifexp) ? op2 : op1);
  3524.  
  3525.   return fold (build (COND_EXPR, result_type, ifexp, op1, op2));
  3526. }
  3527.  
  3528. /* Given a list of expressions, return a compound expression
  3529.    that performs them all and returns the value of the last of them.  */
  3530.  
  3531. tree
  3532. build_compound_expr (list)
  3533.      tree list;
  3534. {
  3535.   return internal_build_compound_expr (list, TRUE);
  3536. }
  3537.  
  3538. static tree
  3539. internal_build_compound_expr (list, first_p)
  3540.      tree list;
  3541.      int first_p;
  3542. {
  3543.   register tree rest;
  3544.  
  3545.   if (TREE_CHAIN (list) == 0)
  3546.     {
  3547. #if 0 /* If something inside inhibited lvalueness, we should not override.  */
  3548.       /* Consider (x, y+0), which is not an lvalue since y+0 is not.  */
  3549.  
  3550.       /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3551.       if (TREE_CODE (list) == NON_LVALUE_EXPR)
  3552.     list = TREE_OPERAND (list, 0);
  3553. #endif
  3554.  
  3555.       /* Don't let (0, 0) be null pointer constant.  */
  3556.       if (!first_p && integer_zerop (TREE_VALUE (list)))
  3557.     return non_lvalue (TREE_VALUE (list));
  3558.       return TREE_VALUE (list);
  3559.     }
  3560.  
  3561.   if (TREE_CHAIN (list) != 0 && TREE_CHAIN (TREE_CHAIN (list)) == 0)
  3562.     {
  3563.       /* Convert arrays to pointers when there really is a comma operator.  */
  3564.       if (TREE_CODE (TREE_TYPE (TREE_VALUE (TREE_CHAIN (list)))) == ARRAY_TYPE)
  3565.     TREE_VALUE (TREE_CHAIN (list))
  3566.       = default_conversion (TREE_VALUE (TREE_CHAIN (list)));
  3567.     }
  3568.  
  3569.   rest = internal_build_compound_expr (TREE_CHAIN (list), FALSE);
  3570.  
  3571.   if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)))
  3572.     {
  3573.       /* The left-hand operand of a comma expression is like an expression
  3574.          statement: with -W or -Wunused, we should warn if it doesn't have
  3575.      any side-effects, unless it was explicitly cast to (void).  */
  3576.       if ((extra_warnings || warn_unused)
  3577.            && ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR
  3578.                 && TREE_TYPE (TREE_VALUE (list)) == void_type_node))
  3579.         warning ("left-hand operand of comma expression has no effect");
  3580.  
  3581.       /* When pedantic, a compound expression can be neither an lvalue
  3582.          nor an integer constant expression.  */
  3583.       if (! pedantic)
  3584.         return rest;
  3585.     }
  3586.  
  3587.   /* With -Wunused, we should also warn if the left-hand operand does have
  3588.      side-effects, but computes a value which is not used.  For example, in
  3589.      `foo() + bar(), baz()' the result of the `+' operator is not used,
  3590.      so we should issue a warning.  */
  3591.   else if (warn_unused)
  3592.     warn_if_unused_value (TREE_VALUE (list));
  3593.  
  3594.   return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest);
  3595. }
  3596.  
  3597. /* Build an expression representing a cast to type TYPE of expression EXPR.  */
  3598.  
  3599. tree
  3600. build_c_cast (type, expr)
  3601.      register tree type;
  3602.      tree expr;
  3603. {
  3604.   register tree value = expr;
  3605.   
  3606.   if (type == error_mark_node || expr == error_mark_node)
  3607.     return error_mark_node;
  3608.   type = TYPE_MAIN_VARIANT (type);
  3609.  
  3610. #if 0
  3611.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3612.   if (TREE_CODE (value) == NON_LVALUE_EXPR)
  3613.     value = TREE_OPERAND (value, 0);
  3614. #endif
  3615.  
  3616.   if (TREE_CODE (type) == ARRAY_TYPE)
  3617.     {
  3618.       error ("cast specifies array type");
  3619.       return error_mark_node;
  3620.     }
  3621.  
  3622.   if (TREE_CODE (type) == FUNCTION_TYPE)
  3623.     {
  3624.       error ("cast specifies function type");
  3625.       return error_mark_node;
  3626.     }
  3627.  
  3628.   if (type == TREE_TYPE (value))
  3629.     {
  3630.       if (pedantic)
  3631.     {
  3632.       if (TREE_CODE (type) == RECORD_TYPE
  3633.           || TREE_CODE (type) == UNION_TYPE)
  3634.         pedwarn ("ANSI C forbids casting nonscalar to the same type");
  3635.     }
  3636.     }
  3637.   else if (TREE_CODE (type) == UNION_TYPE)
  3638.     {
  3639.       tree field;
  3640.       if (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
  3641.       || TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE)
  3642.     value = default_conversion (value);
  3643.  
  3644.       for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
  3645.     if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (field)),
  3646.                TYPE_MAIN_VARIANT (TREE_TYPE (value))))
  3647.       break;
  3648.  
  3649.       if (field)
  3650.     {
  3651.       char *name;
  3652.       tree t;
  3653.  
  3654.       if (pedantic)
  3655.         pedwarn ("ANSI C forbids casts to union type");
  3656.       if (TYPE_NAME (type) != 0)
  3657.         {
  3658.           if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
  3659.         name = IDENTIFIER_POINTER (TYPE_NAME (type));
  3660.           else
  3661.         name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
  3662.         }
  3663.       else
  3664.         name = "";
  3665.       t = digest_init (type, build (CONSTRUCTOR, type, NULL_TREE,
  3666.                     build_tree_list (field, value)),
  3667.                0, 0);
  3668.       TREE_CONSTANT (t) = TREE_CONSTANT (value);
  3669.       return t;
  3670.     }
  3671.       error ("cast to union type from type not present in union");
  3672.       return error_mark_node;
  3673.     }
  3674.   else
  3675.     {
  3676.       tree otype, ovalue;
  3677.  
  3678.       /* If casting to void, avoid the error that would come
  3679.      from default_conversion in the case of a non-lvalue array.  */
  3680.       if (type == void_type_node)
  3681.     return build1 (CONVERT_EXPR, type, value);
  3682.  
  3683.       /* Convert functions and arrays to pointers,
  3684.      but don't convert any other types.  */
  3685.       if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
  3686.       || TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE)
  3687.     value = default_conversion (value);
  3688.       otype = TREE_TYPE (value);
  3689.  
  3690.       /* Optionally warn about potentially worrisome casts.  */
  3691.  
  3692.       if (warn_cast_qual
  3693.       && TREE_CODE (type) == POINTER_TYPE
  3694.       && TREE_CODE (otype) == POINTER_TYPE)
  3695.     {
  3696.       if (TYPE_VOLATILE (TREE_TYPE (otype))
  3697.           && ! TYPE_VOLATILE (TREE_TYPE (type)))
  3698.         pedwarn ("cast discards `volatile' from pointer target type");
  3699.       if (TYPE_READONLY (TREE_TYPE (otype))
  3700.           && ! TYPE_READONLY (TREE_TYPE (type)))
  3701.         pedwarn ("cast discards `const' from pointer target type");
  3702.     }
  3703.  
  3704.       /* Warn about possible alignment problems.  */
  3705.       if (STRICT_ALIGNMENT && warn_cast_align
  3706.       && TREE_CODE (type) == POINTER_TYPE
  3707.       && TREE_CODE (otype) == POINTER_TYPE
  3708.       && TREE_CODE (TREE_TYPE (otype)) != VOID_TYPE
  3709.       && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE
  3710.       && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype)))
  3711.     warning ("cast increases required alignment of target type");
  3712.  
  3713.       if (TREE_CODE (type) == INTEGER_TYPE
  3714.       && TREE_CODE (otype) == POINTER_TYPE
  3715.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
  3716.       && !TREE_CONSTANT (value))
  3717.     warning ("cast from pointer to integer of different size");
  3718.  
  3719.       if (warn_bad_function_cast
  3720.       && TREE_CODE (value) == CALL_EXPR
  3721.       && TREE_CODE (type) != TREE_CODE (otype))
  3722.     warning ("cast does not match function type");
  3723.  
  3724.       if (TREE_CODE (type) == POINTER_TYPE
  3725.       && TREE_CODE (otype) == INTEGER_TYPE
  3726.       && TYPE_PRECISION (type) != TYPE_PRECISION (otype)
  3727. #if 0
  3728.       /* Don't warn about converting 0 to pointer,
  3729.          provided the 0 was explicit--not cast or made by folding.  */
  3730.       && !(TREE_CODE (value) == INTEGER_CST && integer_zerop (value))
  3731. #endif
  3732.       /* Don't warn about converting any constant.  */
  3733.       && !TREE_CONSTANT (value))
  3734.     warning ("cast to pointer from integer of different size");
  3735.  
  3736.       ovalue = value;
  3737.       value = convert (type, value);
  3738.  
  3739.       /* Ignore any integer overflow caused by the cast.  */
  3740.       if (TREE_CODE (value) == INTEGER_CST)
  3741.     {
  3742.       TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
  3743.       TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
  3744.     }
  3745.     }
  3746.  
  3747.   /* Pedantically, don't ley (void *) (FOO *) 0 be a null pointer constant.  */
  3748.   if (pedantic && TREE_CODE (value) == INTEGER_CST
  3749.       && TREE_CODE (expr) == INTEGER_CST
  3750.       && TREE_CODE (TREE_TYPE (expr)) != INTEGER_TYPE)
  3751.     value = non_lvalue (value);
  3752.  
  3753.   /* If pedantic, don't let a cast be an lvalue.  */
  3754.   if (value == expr && pedantic)
  3755.     value = non_lvalue (value);
  3756.  
  3757.   return value;
  3758. }
  3759.  
  3760. /* Build an assignment expression of lvalue LHS from value RHS.
  3761.    MODIFYCODE is the code for a binary operator that we use
  3762.    to combine the old value of LHS with RHS to get the new value.
  3763.    Or else MODIFYCODE is NOP_EXPR meaning do a simple assignment.  */
  3764.  
  3765. tree
  3766. build_modify_expr (lhs, modifycode, rhs)
  3767.      tree lhs, rhs;
  3768.      enum tree_code modifycode;
  3769. {
  3770.   register tree result;
  3771.   tree newrhs;
  3772.   tree lhstype = TREE_TYPE (lhs);
  3773.   tree olhstype = lhstype;
  3774.  
  3775.   /* Types that aren't fully specified cannot be used in assignments.  */
  3776.   lhs = require_complete_type (lhs);
  3777.  
  3778.   /* Avoid duplicate error messages from operands that had errors.  */
  3779.   if (TREE_CODE (lhs) == ERROR_MARK || TREE_CODE (rhs) == ERROR_MARK)
  3780.     return error_mark_node;
  3781.  
  3782.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3783.   /* Do not use STRIP_NOPS here.  We do not want an enumerator
  3784.      whose value is 0 to count as a null pointer constant.  */
  3785.   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
  3786.     rhs = TREE_OPERAND (rhs, 0);
  3787.  
  3788.   newrhs = rhs;
  3789.  
  3790.   /* Handle control structure constructs used as "lvalues".  */
  3791.  
  3792.   switch (TREE_CODE (lhs))
  3793.     {
  3794.       /* Handle (a, b) used as an "lvalue".  */
  3795.     case COMPOUND_EXPR:
  3796.       pedantic_lvalue_warning (COMPOUND_EXPR);
  3797.       newrhs = build_modify_expr (TREE_OPERAND (lhs, 1),
  3798.                   modifycode, rhs);
  3799.       if (TREE_CODE (newrhs) == ERROR_MARK)
  3800.     return error_mark_node;
  3801.       return build (COMPOUND_EXPR, lhstype,
  3802.             TREE_OPERAND (lhs, 0), newrhs);
  3803.  
  3804.       /* Handle (a ? b : c) used as an "lvalue".  */
  3805.     case COND_EXPR:
  3806.       pedantic_lvalue_warning (COND_EXPR);
  3807.       rhs = save_expr (rhs);
  3808.       {
  3809.     /* Produce (a ? (b = rhs) : (c = rhs))
  3810.        except that the RHS goes through a save-expr
  3811.        so the code to compute it is only emitted once.  */
  3812.     tree cond
  3813.       = build_conditional_expr (TREE_OPERAND (lhs, 0),
  3814.                     build_modify_expr (TREE_OPERAND (lhs, 1),
  3815.                                modifycode, rhs),
  3816.                     build_modify_expr (TREE_OPERAND (lhs, 2),
  3817.                                modifycode, rhs));
  3818.     if (TREE_CODE (cond) == ERROR_MARK)
  3819.       return cond;
  3820.     /* Make sure the code to compute the rhs comes out
  3821.        before the split.  */
  3822.     return build (COMPOUND_EXPR, TREE_TYPE (lhs),
  3823.               /* But cast it to void to avoid an "unused" error.  */
  3824.               convert (void_type_node, rhs), cond);
  3825.       }
  3826.     }
  3827.  
  3828.   /* If a binary op has been requested, combine the old LHS value with the RHS
  3829.      producing the value we should actually store into the LHS.  */
  3830.  
  3831.   if (modifycode != NOP_EXPR)
  3832.     {
  3833.       lhs = stabilize_reference (lhs);
  3834.       newrhs = build_binary_op (modifycode, lhs, rhs, 1);
  3835.     }
  3836.  
  3837.   /* Handle a cast used as an "lvalue".
  3838.      We have already performed any binary operator using the value as cast.
  3839.      Now convert the result to the cast type of the lhs,
  3840.      and then true type of the lhs and store it there;
  3841.      then convert result back to the cast type to be the value
  3842.      of the assignment.  */
  3843.  
  3844.   switch (TREE_CODE (lhs))
  3845.     {
  3846.     case NOP_EXPR:
  3847.     case CONVERT_EXPR:
  3848.     case FLOAT_EXPR:
  3849.     case FIX_TRUNC_EXPR:
  3850.     case FIX_FLOOR_EXPR:
  3851.     case FIX_ROUND_EXPR:
  3852.     case FIX_CEIL_EXPR:
  3853.       if (TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
  3854.       || TREE_CODE (TREE_TYPE (newrhs)) == FUNCTION_TYPE)
  3855.     newrhs = default_conversion (newrhs);
  3856.       {
  3857.     tree inner_lhs = TREE_OPERAND (lhs, 0);
  3858.     tree result;
  3859.     result = build_modify_expr (inner_lhs, NOP_EXPR,
  3860.                     convert (TREE_TYPE (inner_lhs),
  3861.                          convert (lhstype, newrhs)));
  3862.     if (TREE_CODE (result) == ERROR_MARK)
  3863.       return result;
  3864.     pedantic_lvalue_warning (CONVERT_EXPR);
  3865.     return convert (TREE_TYPE (lhs), result);
  3866.       }
  3867.     }
  3868.  
  3869.   /* Now we have handled acceptable kinds of LHS that are not truly lvalues.
  3870.      Reject anything strange now.  */
  3871.  
  3872.   if (!lvalue_or_else (lhs, "assignment"))
  3873.     return error_mark_node;
  3874.  
  3875.   /* Warn about storing in something that is `const'.  */
  3876.  
  3877.   if (TREE_READONLY (lhs) || TYPE_READONLY (lhstype)
  3878.       || ((TREE_CODE (lhstype) == RECORD_TYPE
  3879.        || TREE_CODE (lhstype) == UNION_TYPE)
  3880.       && C_TYPE_FIELDS_READONLY (lhstype)))
  3881.     readonly_warning (lhs, "assignment");
  3882.  
  3883.   /* If storing into a structure or union member,
  3884.      it has probably been given type `int'.
  3885.      Compute the type that would go with
  3886.      the actual amount of storage the member occupies.  */
  3887.  
  3888.   if (TREE_CODE (lhs) == COMPONENT_REF
  3889.       && (TREE_CODE (lhstype) == INTEGER_TYPE
  3890.       || TREE_CODE (lhstype) == REAL_TYPE
  3891.       || TREE_CODE (lhstype) == ENUMERAL_TYPE))
  3892.     lhstype = TREE_TYPE (get_unwidened (lhs, 0));
  3893.  
  3894.   /* If storing in a field that is in actuality a short or narrower than one,
  3895.      we must store in the field in its actual type.  */
  3896.  
  3897.   if (lhstype != TREE_TYPE (lhs))
  3898.     {
  3899.       lhs = copy_node (lhs);
  3900.       TREE_TYPE (lhs) = lhstype;
  3901.     }
  3902.  
  3903.   /* Convert new value to destination type.  */
  3904.  
  3905.   newrhs = convert_for_assignment (lhstype, newrhs, "assignment",
  3906.                    NULL_TREE, NULL_TREE, 0);
  3907.   if (TREE_CODE (newrhs) == ERROR_MARK)
  3908.     return error_mark_node;
  3909.  
  3910.   result = build (MODIFY_EXPR, lhstype, lhs, newrhs);
  3911.   TREE_SIDE_EFFECTS (result) = 1;
  3912.  
  3913.   /* If we got the LHS in a different type for storing in,
  3914.      convert the result back to the nominal type of LHS
  3915.      so that the value we return always has the same type
  3916.      as the LHS argument.  */
  3917.  
  3918.   if (olhstype == TREE_TYPE (result))
  3919.     return result;
  3920.   return convert_for_assignment (olhstype, result, "assignment",
  3921.                  NULL_TREE, NULL_TREE, 0);
  3922. }
  3923.  
  3924. /* Convert value RHS to type TYPE as preparation for an assignment
  3925.    to an lvalue of type TYPE.
  3926.    The real work of conversion is done by `convert'.
  3927.    The purpose of this function is to generate error messages
  3928.    for assignments that are not allowed in C.
  3929.    ERRTYPE is a string to use in error messages:
  3930.    "assignment", "return", etc.  If it is null, this is parameter passing
  3931.    for a function call (and different error messages are output).  Otherwise,
  3932.    it may be a name stored in the spelling stack and interpreted by
  3933.    get_spelling.
  3934.  
  3935.    FUNNAME is the name of the function being called,
  3936.    as an IDENTIFIER_NODE, or null.
  3937.    PARMNUM is the number of the argument, for printing in error messages.  */
  3938.  
  3939. static tree
  3940. convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
  3941.      tree type, rhs;
  3942.      char *errtype;
  3943.      tree fundecl, funname;
  3944.      int parmnum;
  3945. {
  3946.   register enum tree_code codel = TREE_CODE (type);
  3947.   register tree rhstype;
  3948.   register enum tree_code coder;
  3949.  
  3950.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  3951.   /* Do not use STRIP_NOPS here.  We do not want an enumerator
  3952.      whose value is 0 to count as a null pointer constant.  */
  3953.   if (TREE_CODE (rhs) == NON_LVALUE_EXPR)
  3954.     rhs = TREE_OPERAND (rhs, 0);
  3955.  
  3956.   if (TREE_CODE (TREE_TYPE (rhs)) == ARRAY_TYPE
  3957.       || TREE_CODE (TREE_TYPE (rhs)) == FUNCTION_TYPE)
  3958.     rhs = default_conversion (rhs);
  3959.   else if (optimize && TREE_CODE (rhs) == VAR_DECL)
  3960.     rhs = decl_constant_value (rhs);
  3961.  
  3962.   rhstype = TREE_TYPE (rhs);
  3963.   coder = TREE_CODE (rhstype);
  3964.  
  3965.   if (coder == ERROR_MARK)
  3966.     return error_mark_node;
  3967.  
  3968.   if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
  3969.     {
  3970.       overflow_warning (rhs);
  3971.       /* Check for Objective-C protocols.  This will issue a warning if
  3972.      there are protocol violations.  No need to use the return value.  */
  3973.       maybe_objc_comptypes (type, rhstype, 0);
  3974.       return rhs;
  3975.     }
  3976.  
  3977.   if (coder == VOID_TYPE)
  3978.     {
  3979.       error ("void value not ignored as it ought to be");
  3980.       return error_mark_node;
  3981.     }
  3982.   /* Arithmetic types all interconvert, and enum is treated like int.  */
  3983.   if ((codel == INTEGER_TYPE || codel == REAL_TYPE || codel == ENUMERAL_TYPE
  3984.        || codel == COMPLEX_TYPE)
  3985.       && (coder == INTEGER_TYPE || coder == REAL_TYPE || coder == ENUMERAL_TYPE
  3986.       || coder == COMPLEX_TYPE))
  3987.     return convert_and_check (type, rhs);
  3988.  
  3989.   /* Conversion to a union from its member types.  */
  3990.   else if (codel == UNION_TYPE)
  3991.     {
  3992.       tree memb_types;
  3993.  
  3994.       for (memb_types = TYPE_FIELDS (type); memb_types;
  3995.        memb_types = TREE_CHAIN (memb_types))
  3996.     {
  3997.       if (comptypes (TREE_TYPE (memb_types), TREE_TYPE (rhs)))
  3998.         {
  3999.           if (pedantic
  4000.           && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl)))
  4001.         pedwarn ("ANSI C prohibits argument conversion to union type");
  4002.           return build1 (NOP_EXPR, type, rhs);
  4003.         }
  4004.  
  4005.       else if (coder == POINTER_TYPE
  4006.            && TREE_CODE (TREE_TYPE (memb_types)) == POINTER_TYPE)
  4007.         {
  4008.           tree memb_type = TREE_TYPE (memb_types);
  4009.           register tree ttl = TREE_TYPE (memb_type);
  4010.           register tree ttr = TREE_TYPE (rhstype);
  4011.  
  4012.           /* Any non-function converts to a [const][volatile] void *
  4013.          and vice versa; otherwise, targets must be the same.
  4014.          Meanwhile, the lhs target must have all the qualifiers of
  4015.          the rhs.  */
  4016.           if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  4017.           || TYPE_MAIN_VARIANT (ttr) == void_type_node
  4018.           || comp_target_types (memb_type, rhstype))
  4019.         {
  4020.           /* Const and volatile mean something different for function
  4021.              types, so the usual warnings are not appropriate.  */
  4022.           if (TREE_CODE (ttr) != FUNCTION_TYPE
  4023.               || TREE_CODE (ttl) != FUNCTION_TYPE)
  4024.             {
  4025.               if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  4026.             warn_for_assignment ("%s discards `const' from pointer target type",
  4027.                          get_spelling (errtype), funname,
  4028.                          parmnum);
  4029.               if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  4030.             warn_for_assignment ("%s discards `volatile' from pointer target type",
  4031.                          get_spelling (errtype), funname,
  4032.                          parmnum);
  4033.             }
  4034.           else
  4035.             {
  4036.               /* Because const and volatile on functions are
  4037.              restrictions that say the function will not do
  4038.              certain things, it is okay to use a const or volatile
  4039.              function where an ordinary one is wanted, but not
  4040.              vice-versa.  */
  4041.               if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr))
  4042.             warn_for_assignment ("%s makes `const *' function pointer from non-const",
  4043.                          get_spelling (errtype), funname,
  4044.                          parmnum);
  4045.               if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
  4046.             warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile",
  4047.                          get_spelling (errtype), funname,
  4048.                          parmnum);
  4049.             }
  4050.  
  4051.           if (pedantic
  4052.               && !(fundecl != 0 && DECL_IN_SYSTEM_HEADER (fundecl)))
  4053.             pedwarn ("ANSI C prohibits argument conversion to union type");
  4054.           return build1 (NOP_EXPR, type, rhs);
  4055.         }
  4056.         }
  4057.  
  4058.       /* Can convert integer zero to any pointer type.  */
  4059.       else if (TREE_CODE (TREE_TYPE (memb_types)) == POINTER_TYPE
  4060.            && (integer_zerop (rhs)
  4061.                || (TREE_CODE (rhs) == NOP_EXPR
  4062.                && integer_zerop (TREE_OPERAND (rhs, 0)))))
  4063.         return build1 (NOP_EXPR, type, null_pointer_node);
  4064.     }
  4065.     }
  4066.  
  4067.   /* Conversions among pointers */
  4068.   else if (codel == POINTER_TYPE && coder == POINTER_TYPE)
  4069.     {
  4070.       register tree ttl = TREE_TYPE (type);
  4071.       register tree ttr = TREE_TYPE (rhstype);
  4072.  
  4073.       /* Any non-function converts to a [const][volatile] void *
  4074.      and vice versa; otherwise, targets must be the same.
  4075.      Meanwhile, the lhs target must have all the qualifiers of the rhs.  */
  4076.       if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  4077.       || TYPE_MAIN_VARIANT (ttr) == void_type_node
  4078.       || comp_target_types (type, rhstype)
  4079.       || (unsigned_type (TYPE_MAIN_VARIANT (ttl))
  4080.           == unsigned_type (TYPE_MAIN_VARIANT (ttr))))
  4081.     {
  4082.       if (pedantic
  4083.           && ((TYPE_MAIN_VARIANT (ttl) == void_type_node
  4084.            && TREE_CODE (ttr) == FUNCTION_TYPE)
  4085.           ||
  4086.           (TYPE_MAIN_VARIANT (ttr) == void_type_node
  4087.            /* Check TREE_CODE to catch cases like (void *) (char *) 0
  4088.               which are not ANSI null ptr constants.  */
  4089.            && (!integer_zerop (rhs) || TREE_CODE (rhs) == NOP_EXPR)
  4090.            && TREE_CODE (ttl) == FUNCTION_TYPE)))
  4091.         warn_for_assignment ("ANSI forbids %s between function pointer and `void *'",
  4092.                  get_spelling (errtype), funname, parmnum);
  4093.       /* Const and volatile mean something different for function types,
  4094.          so the usual warnings are not appropriate.  */
  4095.       else if (TREE_CODE (ttr) != FUNCTION_TYPE
  4096.            && TREE_CODE (ttl) != FUNCTION_TYPE)
  4097.         {
  4098.           if (! TYPE_READONLY (ttl) && TYPE_READONLY (ttr))
  4099.         warn_for_assignment ("%s discards `const' from pointer target type",
  4100.                      get_spelling (errtype), funname, parmnum);
  4101.           else if (! TYPE_VOLATILE (ttl) && TYPE_VOLATILE (ttr))
  4102.         warn_for_assignment ("%s discards `volatile' from pointer target type",
  4103.                      get_spelling (errtype), funname, parmnum);
  4104.           /* If this is not a case of ignoring a mismatch in signedness,
  4105.          no warning.  */
  4106.           else if (TYPE_MAIN_VARIANT (ttl) == void_type_node
  4107.                || TYPE_MAIN_VARIANT (ttr) == void_type_node
  4108.                || comp_target_types (type, rhstype))
  4109.         ;
  4110.           /* If there is a mismatch, do warn.  */
  4111.           else if (pedantic)
  4112.         warn_for_assignment ("pointer targets in %s differ in signedness",
  4113.                      get_spelling (errtype), funname, parmnum);
  4114.         }
  4115.       else if (TREE_CODE (ttl) == FUNCTION_TYPE
  4116.            && TREE_CODE (ttr) == FUNCTION_TYPE)
  4117.         {
  4118.           /* Because const and volatile on functions are restrictions
  4119.          that say the function will not do certain things,
  4120.          it is okay to use a const or volatile function
  4121.          where an ordinary one is wanted, but not vice-versa.  */
  4122.           if (TYPE_READONLY (ttl) && ! TYPE_READONLY (ttr))
  4123.         warn_for_assignment ("%s makes `const *' function pointer from non-const",
  4124.                      get_spelling (errtype), funname, parmnum);
  4125.           if (TYPE_VOLATILE (ttl) && ! TYPE_VOLATILE (ttr))
  4126.         warn_for_assignment ("%s makes `volatile *' function pointer from non-volatile",
  4127.                      get_spelling (errtype), funname, parmnum);
  4128.         }
  4129.     }
  4130.       else
  4131.     warn_for_assignment ("%s from incompatible pointer type",
  4132.                  get_spelling (errtype), funname, parmnum);
  4133.       return convert (type, rhs);
  4134.     }
  4135.   else if (codel == POINTER_TYPE && coder == INTEGER_TYPE)
  4136.     {
  4137.       /* An explicit constant 0 can convert to a pointer,
  4138.      or one that results from arithmetic, even including
  4139.      a cast to integer type.  */
  4140.       if (! (TREE_CODE (rhs) == INTEGER_CST && integer_zerop (rhs))
  4141.       &&
  4142.       ! (TREE_CODE (rhs) == NOP_EXPR
  4143.          && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
  4144.          && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
  4145.          && integer_zerop (TREE_OPERAND (rhs, 0))))
  4146.     {
  4147.       warn_for_assignment ("%s makes pointer from integer without a cast",
  4148.                    get_spelling (errtype), funname, parmnum);
  4149.       return convert (type, rhs);
  4150.     }
  4151.       return null_pointer_node;
  4152.     }
  4153.   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
  4154.     {
  4155.       warn_for_assignment ("%s makes integer from pointer without a cast",
  4156.                get_spelling (errtype), funname, parmnum);
  4157.       return convert (type, rhs);
  4158.     }
  4159.  
  4160.   if (!errtype)
  4161.     {
  4162.       if (funname)
  4163.      {
  4164.        tree selector = maybe_building_objc_message_expr ();
  4165.  
  4166.        if (selector && parmnum > 2)
  4167.          error ("incompatible type for argument %d of `%s'",
  4168.            parmnum - 2, IDENTIFIER_POINTER (selector));
  4169.        else
  4170.         error ("incompatible type for argument %d of `%s'",
  4171.            parmnum, IDENTIFIER_POINTER (funname));
  4172.     }
  4173.       else
  4174.     error ("incompatible type for argument %d of indirect function call",
  4175.            parmnum);
  4176.     }
  4177.   else
  4178.     error ("incompatible types in %s", get_spelling (errtype));
  4179.  
  4180.   return error_mark_node;
  4181. }
  4182.  
  4183. /* Print a warning using MSG.
  4184.    It gets OPNAME as its one parameter.
  4185.    If OPNAME is null, it is replaced by "passing arg ARGNUM of `FUNCTION'".
  4186.    FUNCTION and ARGNUM are handled specially if we are building an
  4187.    Objective-C selector.  */
  4188.  
  4189. static void
  4190. warn_for_assignment (msg, opname, function, argnum)
  4191.      char *msg;
  4192.      char *opname;
  4193.      tree function;
  4194.      int argnum;
  4195. {
  4196.   static char argstring[] = "passing arg %d of `%s'";
  4197.   static char argnofun[] =  "passing arg %d";
  4198.  
  4199.   if (opname == 0)
  4200.     {
  4201.       tree selector = maybe_building_objc_message_expr ();
  4202.       
  4203.       if (selector && argnum > 2)
  4204.     {
  4205.       function = selector;
  4206.       argnum -= 2;
  4207.     }
  4208.       if (function)
  4209.     {
  4210.       /* Function name is known; supply it.  */
  4211.       opname = (char *) alloca (IDENTIFIER_LENGTH (function)
  4212.                     + sizeof (argstring) + 25 /*%d*/ + 1);
  4213.       sprintf (opname, argstring, argnum, IDENTIFIER_POINTER (function));
  4214.     }
  4215.       else
  4216.     {
  4217.       /* Function name unknown (call through ptr); just give arg number.  */
  4218.       opname = (char *) alloca (sizeof (argnofun) + 25 /*%d*/ + 1);
  4219.       sprintf (opname, argnofun, argnum);
  4220.     }
  4221.     }
  4222.   pedwarn (msg, opname);
  4223. }
  4224.  
  4225. /* Return nonzero if VALUE is a valid constant-valued expression
  4226.    for use in initializing a static variable; one that can be an
  4227.    element of a "constant" initializer.
  4228.  
  4229.    Return null_pointer_node if the value is absolute;
  4230.    if it is relocatable, return the variable that determines the relocation.
  4231.    We assume that VALUE has been folded as much as possible;
  4232.    therefore, we do not need to check for such things as
  4233.    arithmetic-combinations of integers.  */
  4234.  
  4235. tree
  4236. initializer_constant_valid_p (value, endtype)
  4237.      tree value;
  4238.      tree endtype;
  4239. {
  4240.   switch (TREE_CODE (value))
  4241.     {
  4242.     case CONSTRUCTOR:
  4243.       if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
  4244.        || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
  4245.       && TREE_CONSTANT (value))
  4246.     return
  4247.       initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
  4248.                     endtype);
  4249.     
  4250.       return TREE_STATIC (value) ? null_pointer_node : 0;
  4251.  
  4252.     case INTEGER_CST:
  4253.     case REAL_CST:
  4254.     case STRING_CST:
  4255.     case COMPLEX_CST:
  4256.       return null_pointer_node;
  4257.  
  4258.     case ADDR_EXPR:
  4259.       return TREE_OPERAND (value, 0);
  4260.  
  4261.     case NON_LVALUE_EXPR:
  4262.       return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
  4263.  
  4264.     case CONVERT_EXPR:
  4265.     case NOP_EXPR:
  4266.       /* Allow conversions between pointer types.  */
  4267.       if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
  4268.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE)
  4269.     return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
  4270.  
  4271.       /* Allow conversions between real types.  */
  4272.       if (TREE_CODE (TREE_TYPE (value)) == REAL_TYPE
  4273.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == REAL_TYPE)
  4274.     return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
  4275.  
  4276.       /* Allow length-preserving conversions between integer types.  */
  4277.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  4278.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
  4279.       && (TYPE_PRECISION (TREE_TYPE (value))
  4280.           == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
  4281.     return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
  4282.  
  4283.       /* Allow conversions between other integer types only if
  4284.      explicit value.  */
  4285.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  4286.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE)
  4287.     {
  4288.       tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4289.                              endtype);
  4290.       if (inner == null_pointer_node)
  4291.         return null_pointer_node;
  4292.       return 0;
  4293.     }
  4294.  
  4295.       /* Allow (int) &foo provided int is as wide as a pointer.  */
  4296.       if (TREE_CODE (TREE_TYPE (value)) == INTEGER_TYPE
  4297.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == POINTER_TYPE
  4298.       && (TYPE_PRECISION (TREE_TYPE (value))
  4299.           >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
  4300.     return initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4301.                          endtype);
  4302.  
  4303.       /* Likewise conversions from int to pointers.  */
  4304.       if (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE
  4305.       && TREE_CODE (TREE_TYPE (TREE_OPERAND (value, 0))) == INTEGER_TYPE
  4306.       && (TYPE_PRECISION (TREE_TYPE (value))
  4307.           <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
  4308.     return initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4309.                          endtype);
  4310.  
  4311.       /* Allow conversions to union types if the value inside is okay.  */
  4312.       if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
  4313.     return initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4314.                          endtype);
  4315.       return 0;
  4316.  
  4317.     case PLUS_EXPR:
  4318.       if (TREE_CODE (endtype) == INTEGER_TYPE
  4319.       && TYPE_PRECISION (endtype) < POINTER_SIZE)
  4320.     return 0;
  4321.       {
  4322.     tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4323.                             endtype);
  4324.     tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
  4325.                             endtype);
  4326.     /* If either term is absolute, use the other terms relocation.  */
  4327.     if (valid0 == null_pointer_node)
  4328.       return valid1;
  4329.     if (valid1 == null_pointer_node)
  4330.       return valid0;
  4331.     return 0;
  4332.       }
  4333.  
  4334.     case MINUS_EXPR:
  4335.       if (TREE_CODE (endtype) == INTEGER_TYPE
  4336.       && TYPE_PRECISION (endtype) < POINTER_SIZE)
  4337.     return 0;
  4338.       {
  4339.     tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
  4340.                             endtype);
  4341.     tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
  4342.                             endtype);
  4343.     /* Win if second argument is absolute.  */
  4344.     if (valid1 == null_pointer_node)
  4345.       return valid0;
  4346.     /* Win if both arguments have the same relocation.
  4347.        Then the value is absolute.  */
  4348.     if (valid0 == valid1)
  4349.       return null_pointer_node;
  4350.     return 0;
  4351.       }
  4352.     }
  4353.  
  4354.   return 0;
  4355. }
  4356.  
  4357. /* If VALUE is a compound expr all of whose expressions are constant, then
  4358.    return its value.  Otherwise, return error_mark_node.
  4359.  
  4360.    This is for handling COMPOUND_EXPRs as initializer elements
  4361.    which is allowed with a warning when -pedantic is specified.  */
  4362.  
  4363. static tree
  4364. valid_compound_expr_initializer (value, endtype)
  4365.      tree value;
  4366.      tree endtype;
  4367. {
  4368.   if (TREE_CODE (value) == COMPOUND_EXPR)
  4369.     {
  4370.       if (valid_compound_expr_initializer (TREE_OPERAND (value, 0), endtype)
  4371.       == error_mark_node)
  4372.     return error_mark_node;
  4373.       return valid_compound_expr_initializer (TREE_OPERAND (value, 1),
  4374.                           endtype);
  4375.     }
  4376.   else if (! TREE_CONSTANT (value)
  4377.        && ! initializer_constant_valid_p (value, endtype))
  4378.     return error_mark_node;
  4379.   else
  4380.     return value;
  4381. }
  4382.  
  4383. /* Perform appropriate conversions on the initial value of a variable,
  4384.    store it in the declaration DECL,
  4385.    and print any error messages that are appropriate.
  4386.    If the init is invalid, store an ERROR_MARK.  */
  4387.  
  4388. void
  4389. store_init_value (decl, init)
  4390.      tree decl, init;
  4391. {
  4392.   register tree value, type;
  4393.  
  4394.   /* If variable's type was invalidly declared, just ignore it.  */
  4395.  
  4396.   type = TREE_TYPE (decl);
  4397.   if (TREE_CODE (type) == ERROR_MARK)
  4398.     return;
  4399.  
  4400.   /* Digest the specified initializer into an expression.  */
  4401.  
  4402.   value = digest_init (type, init, TREE_STATIC (decl),
  4403.                TREE_STATIC (decl) || pedantic);
  4404.  
  4405.   /* Store the expression if valid; else report error.  */
  4406.  
  4407. #if 0
  4408.   /* Note that this is the only place we can detect the error
  4409.      in a case such as   struct foo bar = (struct foo) { x, y };
  4410.      where there is one initial value which is a constructor expression.  */
  4411.   if (value == error_mark_node)
  4412.     ;
  4413.   else if (TREE_STATIC (decl) && ! TREE_CONSTANT (value))
  4414.     {
  4415.       error ("initializer for static variable is not constant");
  4416.       value = error_mark_node;
  4417.     }
  4418.   else if (TREE_STATIC (decl)
  4419.        && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
  4420.     {
  4421.       error ("initializer for static variable uses complicated arithmetic");
  4422.       value = error_mark_node;
  4423.     }
  4424.   else
  4425.     {
  4426.       if (pedantic && TREE_CODE (value) == CONSTRUCTOR)
  4427.     {
  4428.       if (! TREE_CONSTANT (value))
  4429.         pedwarn ("aggregate initializer is not constant");
  4430.       else if (! TREE_STATIC (value))
  4431.         pedwarn ("aggregate initializer uses complicated arithmetic");
  4432.     }
  4433.     }
  4434. #endif
  4435.  
  4436.   DECL_INITIAL (decl) = value;
  4437.  
  4438.   /* ANSI wants warnings about out-of-range constant initializers.  */
  4439.   STRIP_TYPE_NOPS (value);
  4440.   constant_expression_warning (value);
  4441. }
  4442.  
  4443. /* Methods for storing and printing names for error messages.  */
  4444.  
  4445. /* Implement a spelling stack that allows components of a name to be pushed
  4446.    and popped.  Each element on the stack is this structure.  */
  4447.  
  4448. struct spelling
  4449. {
  4450.   int kind;
  4451.   union
  4452.     {
  4453.       int i;
  4454.       char *s;
  4455.     } u;
  4456. };
  4457.  
  4458. #define SPELLING_STRING 1
  4459. #define SPELLING_MEMBER 2
  4460. #define SPELLING_BOUNDS 3
  4461.  
  4462. static struct spelling *spelling;    /* Next stack element (unused).  */
  4463. static struct spelling *spelling_base;    /* Spelling stack base.  */
  4464. static int spelling_size;        /* Size of the spelling stack.  */
  4465.  
  4466. /* Macros to save and restore the spelling stack around push_... functions.
  4467.    Alternative to SAVE_SPELLING_STACK.  */
  4468.  
  4469. #define SPELLING_DEPTH() (spelling - spelling_base)
  4470. #define RESTORE_SPELLING_DEPTH(depth) (spelling = spelling_base + depth)
  4471.  
  4472. /* Save and restore the spelling stack around arbitrary C code.  */
  4473.  
  4474. #define SAVE_SPELLING_DEPTH(code)        \
  4475. {                        \
  4476.   int __depth = SPELLING_DEPTH ();        \
  4477.   code;                        \
  4478.   RESTORE_SPELLING_DEPTH (__depth);        \
  4479. }
  4480.  
  4481. /* Push an element on the spelling stack with type KIND and assign VALUE
  4482.    to MEMBER.  */
  4483.  
  4484. #define PUSH_SPELLING(KIND, VALUE, MEMBER)                \
  4485. {                                    \
  4486.   int depth = SPELLING_DEPTH ();                    \
  4487.                                     \
  4488.   if (depth >= spelling_size)                        \
  4489.     {                                    \
  4490.       spelling_size += 10;                        \
  4491.       if (spelling_base == 0)                        \
  4492.     spelling_base                            \
  4493.       = (struct spelling *) xmalloc (spelling_size * sizeof (struct spelling));    \
  4494.       else                                \
  4495.         spelling_base                            \
  4496.       = (struct spelling *) xrealloc (spelling_base,        \
  4497.                       spelling_size * sizeof (struct spelling));    \
  4498.       RESTORE_SPELLING_DEPTH (depth);                    \
  4499.     }                                    \
  4500.                                     \
  4501.   spelling->kind = (KIND);                        \
  4502.   spelling->MEMBER = (VALUE);                        \
  4503.   spelling++;                                \
  4504. }
  4505.  
  4506. /* Push STRING on the stack.  Printed literally.  */
  4507.  
  4508. static void
  4509. push_string (string)
  4510.      char *string;
  4511. {
  4512.   PUSH_SPELLING (SPELLING_STRING, string, u.s);
  4513. }
  4514.  
  4515. /* Push a member name on the stack.  Printed as '.' STRING.  */
  4516.  
  4517. static void
  4518. push_member_name (decl)
  4519.      tree decl;
  4520.      
  4521. {
  4522.   char *string
  4523.     = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
  4524.   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
  4525. }
  4526.  
  4527. /* Push an array bounds on the stack.  Printed as [BOUNDS].  */
  4528.  
  4529. static void
  4530. push_array_bounds (bounds)
  4531.      int bounds;
  4532. {
  4533.   PUSH_SPELLING (SPELLING_BOUNDS, bounds, u.i);
  4534. }
  4535.  
  4536. /* Compute the maximum size in bytes of the printed spelling.  */
  4537.  
  4538. static int
  4539. spelling_length ()
  4540. {
  4541.   register int size = 0;
  4542.   register struct spelling *p;
  4543.  
  4544.   for (p = spelling_base; p < spelling; p++)
  4545.     {
  4546.       if (p->kind == SPELLING_BOUNDS)
  4547.     size += 25;
  4548.       else
  4549.     size += strlen (p->u.s) + 1;
  4550.     }
  4551.  
  4552.   return size;
  4553. }
  4554.  
  4555. /* Print the spelling to BUFFER and return it.  */
  4556.  
  4557. static char *
  4558. print_spelling (buffer)
  4559.      register char *buffer;
  4560. {
  4561.   register char *d = buffer;
  4562.   register char *s;
  4563.   register struct spelling *p;
  4564.  
  4565.   for (p = spelling_base; p < spelling; p++)
  4566.     if (p->kind == SPELLING_BOUNDS)
  4567.       {
  4568.     sprintf (d, "[%d]", p->u.i);
  4569.     d += strlen (d);
  4570.       }
  4571.     else
  4572.       {
  4573.     if (p->kind == SPELLING_MEMBER)
  4574.       *d++ = '.';
  4575.     for (s = p->u.s; *d = *s++; d++)
  4576.       ;
  4577.       }
  4578.   *d++ = '\0';
  4579.   return buffer;
  4580. }
  4581.  
  4582. /* Provide a means to pass component names derived from the spelling stack.  */
  4583.  
  4584. char initialization_message;
  4585.  
  4586. /* Interpret the spelling of the given ERRTYPE message.  */
  4587.  
  4588. static char *
  4589. get_spelling (errtype)
  4590.      char *errtype;
  4591. {
  4592.   static char *buffer;
  4593.   static int size = -1;
  4594.  
  4595.   if (errtype == &initialization_message)
  4596.     {
  4597.       /* Avoid counting chars */
  4598.       static char message[] = "initialization of `%s'";
  4599.       register int needed = sizeof (message) + spelling_length () + 1;
  4600.       char *temp;
  4601.  
  4602.       if (size < 0)
  4603.     buffer = (char *) xmalloc (size = needed);
  4604.       if (needed > size)
  4605.     buffer = (char *) xrealloc (buffer, size = needed);
  4606.  
  4607.       temp = (char *) alloca (needed);
  4608.       sprintf (buffer, message, print_spelling (temp));
  4609.       return buffer;
  4610.     }
  4611.  
  4612.   return errtype;
  4613. }
  4614.  
  4615. /* Issue an error message for a bad initializer component.
  4616.    FORMAT describes the message.  OFWHAT is the name for the component.
  4617.    LOCAL is a format string for formatting the insertion of the name
  4618.    into the message.
  4619.  
  4620.    If OFWHAT is null, the component name is stored on the spelling stack.
  4621.    If the component name is a null string, then LOCAL is omitted entirely.  */
  4622.  
  4623. void
  4624. error_init (format, local, ofwhat)
  4625.      char *format, *local, *ofwhat;
  4626. {
  4627.   char *buffer;
  4628.  
  4629.   if (ofwhat == 0)
  4630.     ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
  4631.   buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
  4632.  
  4633.   if (*ofwhat)
  4634.     sprintf (buffer, local, ofwhat);
  4635.   else
  4636.     buffer[0] = 0;
  4637.  
  4638.   error (format, buffer);
  4639. }
  4640.  
  4641. /* Issue a pedantic warning for a bad initializer component.
  4642.    FORMAT describes the message.  OFWHAT is the name for the component.
  4643.    LOCAL is a format string for formatting the insertion of the name
  4644.    into the message.
  4645.  
  4646.    If OFWHAT is null, the component name is stored on the spelling stack.
  4647.    If the component name is a null string, then LOCAL is omitted entirely.  */
  4648.  
  4649. void
  4650. pedwarn_init (format, local, ofwhat)
  4651.      char *format, *local, *ofwhat;
  4652. {
  4653.   char *buffer;
  4654.  
  4655.   if (ofwhat == 0)
  4656.     ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
  4657.   buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
  4658.  
  4659.   if (*ofwhat)
  4660.     sprintf (buffer, local, ofwhat);
  4661.   else
  4662.     buffer[0] = 0;
  4663.  
  4664.   pedwarn (format, buffer);
  4665. }
  4666.  
  4667. /* Issue a warning for a bad initializer component.
  4668.    FORMAT describes the message.  OFWHAT is the name for the component.
  4669.    LOCAL is a format string for formatting the insertion of the name
  4670.    into the message.
  4671.  
  4672.    If OFWHAT is null, the component name is stored on the spelling stack.
  4673.    If the component name is a null string, then LOCAL is omitted entirely.  */
  4674.  
  4675. static void
  4676. warning_init (format, local, ofwhat)
  4677.      char *format, *local, *ofwhat;
  4678. {
  4679.   char *buffer;
  4680.  
  4681.   if (ofwhat == 0)
  4682.     ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
  4683.   buffer = (char *) alloca (strlen (local) + strlen (ofwhat) + 2);
  4684.  
  4685.   if (*ofwhat)
  4686.     sprintf (buffer, local, ofwhat);
  4687.   else
  4688.     buffer[0] = 0;
  4689.  
  4690.   warning (format, buffer);
  4691. }
  4692.  
  4693. /* Digest the parser output INIT as an initializer for type TYPE.
  4694.    Return a C expression of type TYPE to represent the initial value.
  4695.  
  4696.    The arguments REQUIRE_CONSTANT and CONSTRUCTOR_CONSTANT request errors
  4697.    if non-constant initializers or elements are seen.  CONSTRUCTOR_CONSTANT
  4698.    applies only to elements of constructors.  */
  4699.  
  4700. static tree
  4701. digest_init (type, init, require_constant, constructor_constant)
  4702.      tree type, init;
  4703.      int require_constant, constructor_constant;
  4704. {
  4705.   enum tree_code code = TREE_CODE (type);
  4706.   tree inside_init = init;
  4707.  
  4708.   if (init == error_mark_node)
  4709.     return init;
  4710.  
  4711.   /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue.  */
  4712.   /* Do not use STRIP_NOPS here.  We do not want an enumerator
  4713.      whose value is 0 to count as a null pointer constant.  */
  4714.   if (TREE_CODE (init) == NON_LVALUE_EXPR)
  4715.     inside_init = TREE_OPERAND (init, 0);
  4716.  
  4717.   /* Initialization of an array of chars from a string constant
  4718.      optionally enclosed in braces.  */
  4719.  
  4720.   if (code == ARRAY_TYPE)
  4721.     {
  4722.       tree typ1 = TYPE_MAIN_VARIANT (TREE_TYPE (type));
  4723.       if ((typ1 == char_type_node
  4724.        || typ1 == signed_char_type_node
  4725.        || typ1 == unsigned_char_type_node
  4726.        || typ1 == unsigned_wchar_type_node
  4727.        || typ1 == signed_wchar_type_node)
  4728.       && ((inside_init && TREE_CODE (inside_init) == STRING_CST)))
  4729.     {
  4730.       if (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
  4731.              TYPE_MAIN_VARIANT (type)))
  4732.         return inside_init;
  4733.  
  4734.       if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
  4735.            != char_type_node)
  4736.           && TYPE_PRECISION (typ1) == TYPE_PRECISION (char_type_node))
  4737.         {
  4738.           error_init ("char-array%s initialized from wide string",
  4739.               " `%s'", NULL);
  4740.           return error_mark_node;
  4741.         }
  4742.       if ((TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (inside_init)))
  4743.            == char_type_node)
  4744.           && TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node))
  4745.         {
  4746.           error_init ("int-array%s initialized from non-wide string",
  4747.               " `%s'", NULL);
  4748.           return error_mark_node;
  4749.         }
  4750.  
  4751.       TREE_TYPE (inside_init) = type;
  4752.       if (TYPE_DOMAIN (type) != 0
  4753.           && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
  4754.         {
  4755.           register int size = TREE_INT_CST_LOW (TYPE_SIZE (type));
  4756.           size = (size + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  4757.           /* Subtract 1 (or sizeof (wchar_t))
  4758.          because it's ok to ignore the terminating null char
  4759.          that is counted in the length of the constant.  */
  4760.           if (size < TREE_STRING_LENGTH (inside_init)
  4761.           - (TYPE_PRECISION (typ1) != TYPE_PRECISION (char_type_node)
  4762.              ? TYPE_PRECISION (wchar_type_node) / BITS_PER_UNIT
  4763.              : 1))
  4764.         pedwarn_init (
  4765.           "initializer-string for array of chars%s is too long",
  4766.           " `%s'", NULL);
  4767.         }
  4768.       return inside_init;
  4769.     }
  4770.     }
  4771.  
  4772.   /* Any type can be initialized
  4773.      from an expression of the same type, optionally with braces.  */
  4774.  
  4775.   if (inside_init && TREE_TYPE (inside_init) != 0
  4776.       && (comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (inside_init)),
  4777.              TYPE_MAIN_VARIANT (type))
  4778.       || (code == ARRAY_TYPE
  4779.           && comptypes (TREE_TYPE (inside_init), type))
  4780.       || (code == POINTER_TYPE
  4781.           && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
  4782.           || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE)
  4783.           && comptypes (TREE_TYPE (TREE_TYPE (inside_init)),
  4784.                 TREE_TYPE (type)))))
  4785.     {
  4786.       if (code == POINTER_TYPE
  4787.       && (TREE_CODE (TREE_TYPE (inside_init)) == ARRAY_TYPE
  4788.           || TREE_CODE (TREE_TYPE (inside_init)) == FUNCTION_TYPE))
  4789.     inside_init = default_conversion (inside_init);
  4790.       else if (code == ARRAY_TYPE && TREE_CODE (inside_init) != STRING_CST
  4791.            && TREE_CODE (inside_init) != CONSTRUCTOR)
  4792.     {
  4793.       error_init ("array%s initialized from non-constant array expression",
  4794.               " `%s'", NULL);
  4795.       return error_mark_node;
  4796.     }
  4797.  
  4798.       if (optimize && TREE_CODE (inside_init) == VAR_DECL)
  4799.     inside_init = decl_constant_value (inside_init);
  4800.  
  4801.       /* Compound expressions can only occur here if -pedantic or
  4802.      -pedantic-errors is specified.  In the later case, we always want
  4803.      an error.  In the former case, we simply want a warning.  */
  4804.       if (require_constant && pedantic
  4805.       && TREE_CODE (inside_init) == COMPOUND_EXPR)
  4806.     {
  4807.       inside_init
  4808.         = valid_compound_expr_initializer (inside_init,
  4809.                            TREE_TYPE (inside_init));
  4810.       if (inside_init == error_mark_node)
  4811.         error_init ("initializer element%s is not constant",
  4812.             " for `%s'", NULL);
  4813.       else
  4814.         pedwarn_init ("initializer element%s is not constant",
  4815.               " for `%s'", NULL);
  4816.       if (flag_pedantic_errors)
  4817.         inside_init = error_mark_node;
  4818.     }
  4819.       else if (require_constant && ! TREE_CONSTANT (inside_init))
  4820.     {
  4821.       error_init ("initializer element%s is not constant",
  4822.               " for `%s'", NULL);
  4823.       inside_init = error_mark_node;
  4824.     }
  4825.       else if (require_constant
  4826.            && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
  4827.     {
  4828.       error_init ("initializer element%s is not computable at load time",
  4829.               " for `%s'", NULL);
  4830.       inside_init = error_mark_node;
  4831.     }
  4832.  
  4833.       return inside_init;
  4834.     }
  4835.  
  4836.   /* Handle scalar types, including conversions.  */
  4837.  
  4838.   if (code == INTEGER_TYPE || code == REAL_TYPE || code == POINTER_TYPE
  4839.       || code == ENUMERAL_TYPE || code == COMPLEX_TYPE)
  4840.     {
  4841.       /* Note that convert_for_assignment calls default_conversion
  4842.      for arrays and functions.  We must not call it in the
  4843.      case where inside_init is a null pointer constant.  */
  4844.       inside_init
  4845.     = convert_for_assignment (type, init, "initialization",
  4846.                   NULL_TREE, NULL_TREE, 0);
  4847.  
  4848.       if (require_constant && ! TREE_CONSTANT (inside_init))
  4849.     {
  4850.       error_init ("initializer element%s is not constant",
  4851.               " for `%s'", NULL);
  4852.       inside_init = error_mark_node;
  4853.     }
  4854.       else if (require_constant
  4855.            && initializer_constant_valid_p (inside_init, TREE_TYPE (inside_init)) == 0)
  4856.     {
  4857.       error_init ("initializer element%s is not computable at load time",
  4858.               " for `%s'", NULL);
  4859.       inside_init = error_mark_node;
  4860.     }
  4861.  
  4862.       return inside_init;
  4863.     }
  4864.  
  4865.   /* Come here only for records and arrays.  */
  4866.  
  4867.   if (TYPE_SIZE (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
  4868.     {
  4869.       error_init ("variable-sized object%s may not be initialized",
  4870.           " `%s'", NULL);
  4871.       return error_mark_node;
  4872.     }
  4873.  
  4874.   /* Traditionally, you can write  struct foo x = 0;
  4875.      and it initializes the first element of x to 0.  */
  4876.   if (flag_traditional)
  4877.     {
  4878.       tree top = 0, prev = 0;
  4879.       while (TREE_CODE (type) == RECORD_TYPE
  4880.          || TREE_CODE (type) == ARRAY_TYPE
  4881.          || TREE_CODE (type) == QUAL_UNION_TYPE
  4882.          || TREE_CODE (type) == UNION_TYPE)
  4883.     {
  4884.       tree temp = build (CONSTRUCTOR, type, NULL_TREE, NULL_TREE);
  4885.       if (prev == 0)
  4886.         top = temp;
  4887.       else
  4888.         TREE_OPERAND (prev, 1) = build_tree_list (NULL_TREE, temp);
  4889.       prev = temp;
  4890.       if (TREE_CODE (type) == ARRAY_TYPE)
  4891.         type = TREE_TYPE (type);
  4892.       else if (TYPE_FIELDS (type))
  4893.         type = TREE_TYPE (TYPE_FIELDS (type));
  4894.       else
  4895.         {
  4896.           error_init ("invalid initializer%s", " for `%s'", NULL);
  4897.           return error_mark_node;
  4898.         }
  4899.     }
  4900.       TREE_OPERAND (prev, 1)
  4901.     = build_tree_list (NULL_TREE,
  4902.                digest_init (type, init, require_constant,
  4903.                     constructor_constant));
  4904.       return top;
  4905.     }
  4906.   error_init ("invalid initializer%s", " for `%s'", NULL);
  4907.   return error_mark_node;
  4908. }
  4909.  
  4910. /* Handle initializers that use braces.  */
  4911.  
  4912. /* Type of object we are accumulating a constructor for.
  4913.    This type is always a RECORD_TYPE, UNION_TYPE or ARRAY_TYPE.  */
  4914. static tree constructor_type;
  4915.  
  4916. /* For a RECORD_TYPE or UNION_TYPE, this is the chain of fields
  4917.    left to fill.  */
  4918. static tree constructor_fields;
  4919.  
  4920. /* For an ARRAY_TYPE, this is the specified index
  4921.    at which to store the next element we get.
  4922.    This is a special INTEGER_CST node that we modify in place.  */
  4923. static tree constructor_index;
  4924.  
  4925. /* For an ARRAY_TYPE, this is the end index of the range
  4926.    to initialize with the next element, or NULL in the ordinary case
  4927.    where the element is used just once.  */
  4928. static tree constructor_range_end;
  4929.  
  4930. /* For an ARRAY_TYPE, this is the maximum index.  */
  4931. static tree constructor_max_index;
  4932.  
  4933. /* For a RECORD_TYPE, this is the first field not yet written out.  */
  4934. static tree constructor_unfilled_fields;
  4935.  
  4936. /* For an ARRAY_TYPE, this is the index of the first element
  4937.    not yet written out.
  4938.    This is a special INTEGER_CST node that we modify in place.  */
  4939. static tree constructor_unfilled_index;
  4940.  
  4941. /* In a RECORD_TYPE, the byte index of the next consecutive field.
  4942.    This is so we can generate gaps between fields, when appropriate.
  4943.    This is a special INTEGER_CST node that we modify in place.  */
  4944. static tree constructor_bit_index;
  4945.  
  4946. /* If we are saving up the elements rather than allocating them,
  4947.    this is the list of elements so far (in reverse order,
  4948.    most recent first).  */
  4949. static tree constructor_elements;
  4950.  
  4951. /* 1 if so far this constructor's elements are all compile-time constants.  */
  4952. static int constructor_constant;
  4953.  
  4954. /* 1 if so far this constructor's elements are all valid address constants.  */
  4955. static int constructor_simple;
  4956.  
  4957. /* 1 if this constructor is erroneous so far.  */
  4958. static int constructor_erroneous;
  4959.  
  4960. /* 1 if have called defer_addressed_constants.  */
  4961. static int constructor_subconstants_deferred;
  4962.  
  4963. /* List of pending elements at this constructor level.
  4964.    These are elements encountered out of order
  4965.    which belong at places we haven't reached yet in actually
  4966.    writing the output.  */
  4967. static tree constructor_pending_elts;
  4968.  
  4969. /* The SPELLING_DEPTH of this constructor.  */
  4970. static int constructor_depth;
  4971.  
  4972. /* 0 if implicitly pushing constructor levels is allowed.  */
  4973. int constructor_no_implicit = 0; /* 0 for C; 1 for some other languages. */
  4974.  
  4975. /* 1 if this constructor level was entered implicitly.  */
  4976. static int constructor_implicit;
  4977.  
  4978. static int require_constant_value;
  4979. static int require_constant_elements;
  4980.  
  4981. /* 1 if it is ok to output this constructor as we read it.
  4982.    0 means must accumulate a CONSTRUCTOR expression.  */
  4983. static int constructor_incremental;
  4984.  
  4985. /* DECL node for which an initializer is being read.
  4986.    0 means we are reading a constructor expression
  4987.    such as (struct foo) {...}.  */
  4988. static tree constructor_decl;
  4989.  
  4990. /* start_init saves the ASMSPEC arg here for really_start_incremental_init.  */
  4991. static char *constructor_asmspec;
  4992.  
  4993. /* Nonzero if this is an initializer for a top-level decl.  */
  4994. static int constructor_top_level;
  4995.  
  4996. /* When we finish reading a constructor expression
  4997.    (constructor_decl is 0), the CONSTRUCTOR goes here.  */
  4998. static tree constructor_result;
  4999.  
  5000. /* This stack has a level for each implicit or explicit level of
  5001.    structuring in the initializer, including the outermost one.  It
  5002.    saves the values of most of the variables above.  */
  5003.  
  5004. struct constructor_stack
  5005. {
  5006.   struct constructor_stack *next;
  5007.   tree type;
  5008.   tree fields;
  5009.   tree index;
  5010.   tree range_end;
  5011.   tree max_index;
  5012.   tree unfilled_index;
  5013.   tree unfilled_fields;
  5014.   tree bit_index;
  5015.   tree elements;
  5016.   int offset;
  5017.   tree pending_elts;
  5018.   int depth;
  5019.   /* If nonzero, this value should replace the entire
  5020.      constructor at this level.  */
  5021.   tree replacement_value;
  5022.   char constant;
  5023.   char simple;
  5024.   char implicit;
  5025.   char incremental;
  5026.   char erroneous;
  5027.   char outer;
  5028. };
  5029.  
  5030. struct constructor_stack *constructor_stack;
  5031.  
  5032. /* This stack records separate initializers that are nested.
  5033.    Nested initializers can't happen in ANSI C, but GNU C allows them
  5034.    in cases like { ... (struct foo) { ... } ... }.  */
  5035.  
  5036. struct initializer_stack
  5037. {
  5038.   struct initializer_stack *next;
  5039.   tree decl;
  5040.   char *asmspec;
  5041.   struct constructor_stack *constructor_stack;
  5042.   tree elements;
  5043.   struct spelling *spelling;
  5044.   struct spelling *spelling_base;
  5045.   int spelling_size;
  5046.   char top_level;
  5047.   char incremental;
  5048.   char require_constant_value;
  5049.   char require_constant_elements;
  5050.   char deferred;
  5051. };
  5052.  
  5053. struct initializer_stack *initializer_stack;
  5054.  
  5055. /* Prepare to parse and output the initializer for variable DECL.  */
  5056.  
  5057. void
  5058. start_init (decl, asmspec_tree, top_level)
  5059.      tree decl;
  5060.      tree asmspec_tree;
  5061.      int top_level;
  5062. {
  5063.   char *locus;
  5064.   struct initializer_stack *p
  5065.     = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
  5066.   char *asmspec = 0;
  5067.  
  5068.   if (asmspec_tree)
  5069.     asmspec = TREE_STRING_POINTER (asmspec_tree);
  5070.  
  5071.   p->decl = constructor_decl;
  5072.   p->asmspec = constructor_asmspec;
  5073.   p->incremental = constructor_incremental;
  5074.   p->require_constant_value = require_constant_value;
  5075.   p->require_constant_elements = require_constant_elements;
  5076.   p->constructor_stack = constructor_stack;
  5077.   p->elements = constructor_elements;
  5078.   p->spelling = spelling;
  5079.   p->spelling_base = spelling_base;
  5080.   p->spelling_size = spelling_size;
  5081.   p->deferred = constructor_subconstants_deferred;
  5082.   p->top_level = constructor_top_level;
  5083.   p->next = initializer_stack;
  5084.   initializer_stack = p;
  5085.  
  5086.   constructor_decl = decl;
  5087.   constructor_incremental = top_level;
  5088.   constructor_asmspec = asmspec;
  5089.   constructor_subconstants_deferred = 0;
  5090.   constructor_top_level = top_level;
  5091.  
  5092.   if (decl != 0)
  5093.     {
  5094.       require_constant_value = TREE_STATIC (decl);
  5095.       require_constant_elements
  5096.     = ((TREE_STATIC (decl) || pedantic)
  5097.        /* For a scalar, you can always use any value to initialize,
  5098.           even within braces.  */
  5099.        && (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  5100.            || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  5101.            || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
  5102.            || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE));
  5103.       locus = IDENTIFIER_POINTER (DECL_NAME (decl));
  5104.       constructor_incremental |= TREE_STATIC (decl);
  5105.     }
  5106.   else
  5107.     {
  5108.       require_constant_value = 0;
  5109.       require_constant_elements = 0;
  5110.       locus = "(anonymous)";
  5111.     }
  5112.  
  5113.   constructor_stack = 0;
  5114.  
  5115.   missing_braces_mentioned = 0;
  5116.  
  5117.   spelling_base = 0;
  5118.   spelling_size = 0;
  5119.   RESTORE_SPELLING_DEPTH (0);
  5120.  
  5121.   if (locus)
  5122.     push_string (locus);
  5123. }
  5124.  
  5125. void
  5126. finish_init ()
  5127. {
  5128.   struct initializer_stack *p = initializer_stack;
  5129.  
  5130.   /* Output subconstants (string constants, usually)
  5131.      that were referenced within this initializer and saved up.
  5132.      Must do this if and only if we called defer_addressed_constants.  */
  5133.   if (constructor_subconstants_deferred)
  5134.     output_deferred_addressed_constants ();
  5135.  
  5136.   /* Free the whole constructor stack of this initializer.  */
  5137.   while (constructor_stack)
  5138.     {
  5139.       struct constructor_stack *q = constructor_stack;
  5140.       constructor_stack = q->next;
  5141.       free (q);
  5142.     }
  5143.  
  5144.   /* Pop back to the data of the outer initializer (if any).  */
  5145.   constructor_decl = p->decl;
  5146.   constructor_asmspec = p->asmspec;
  5147.   constructor_incremental = p->incremental;
  5148.   require_constant_value = p->require_constant_value;
  5149.   require_constant_elements = p->require_constant_elements;
  5150.   constructor_stack = p->constructor_stack;
  5151.   constructor_elements = p->elements;
  5152.   spelling = p->spelling;
  5153.   spelling_base = p->spelling_base;
  5154.   spelling_size = p->spelling_size;
  5155.   constructor_subconstants_deferred = p->deferred;
  5156.   constructor_top_level = p->top_level;
  5157.   initializer_stack = p->next;
  5158.   free (p);
  5159. }
  5160.  
  5161. /* Call here when we see the initializer is surrounded by braces.
  5162.    This is instead of a call to push_init_level;
  5163.    it is matched by a call to pop_init_level.
  5164.  
  5165.    TYPE is the type to initialize, for a constructor expression.
  5166.    For an initializer for a decl, TYPE is zero.  */
  5167.  
  5168. void
  5169. really_start_incremental_init (type)
  5170.      tree type;
  5171. {
  5172.   struct constructor_stack *p
  5173.     = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
  5174.  
  5175.   if (type == 0)
  5176.     type = TREE_TYPE (constructor_decl);
  5177.  
  5178.   /* Turn off constructor_incremental if type is a struct with bitfields.
  5179.      Do this before the first push, so that the corrected value
  5180.      is available in finish_init.  */
  5181.   check_init_type_bitfields (type);
  5182.  
  5183.   p->type = constructor_type;
  5184.   p->fields = constructor_fields;
  5185.   p->index = constructor_index;
  5186.   p->range_end = constructor_range_end;
  5187.   p->max_index = constructor_max_index;
  5188.   p->unfilled_index = constructor_unfilled_index;
  5189.   p->unfilled_fields = constructor_unfilled_fields;
  5190.   p->bit_index = constructor_bit_index;
  5191.   p->elements = constructor_elements;
  5192.   p->constant = constructor_constant;
  5193.   p->simple = constructor_simple;
  5194.   p->erroneous = constructor_erroneous;
  5195.   p->pending_elts = constructor_pending_elts;
  5196.   p->depth = constructor_depth;
  5197.   p->replacement_value = 0;
  5198.   p->implicit = 0;
  5199.   p->incremental = constructor_incremental;
  5200.   p->outer = 0;
  5201.   p->next = 0;
  5202.   constructor_stack = p;
  5203.  
  5204.   constructor_constant = 1;
  5205.   constructor_simple = 1;
  5206.   constructor_depth = SPELLING_DEPTH ();
  5207.   constructor_elements = 0;
  5208.   constructor_pending_elts = 0;
  5209.   constructor_type = type;
  5210.  
  5211.   if (TREE_CODE (constructor_type) == RECORD_TYPE
  5212.       || TREE_CODE (constructor_type) == UNION_TYPE)
  5213.     {
  5214.       constructor_fields = TYPE_FIELDS (constructor_type);
  5215.       /* Skip any nameless bit fields atthe beginning.  */
  5216.       while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
  5217.          && DECL_NAME (constructor_fields) == 0)
  5218.     constructor_fields = TREE_CHAIN (constructor_fields);
  5219.       constructor_unfilled_fields = constructor_fields;
  5220.       constructor_bit_index = copy_node (integer_zero_node);
  5221.     }
  5222.   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5223.     {
  5224.       constructor_range_end = 0;
  5225.       if (TYPE_DOMAIN (constructor_type))
  5226.     {
  5227.       constructor_max_index
  5228.         = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
  5229.       constructor_index
  5230.         = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
  5231.     }
  5232.       else
  5233.     constructor_index = copy_node (integer_zero_node);
  5234.       constructor_unfilled_index = copy_node (constructor_index);
  5235.     }
  5236.   else
  5237.     {
  5238.       /* Handle the case of int x = {5}; */
  5239.       constructor_fields = constructor_type;
  5240.       constructor_unfilled_fields = constructor_type;
  5241.     }
  5242.  
  5243.   if (constructor_incremental)
  5244.     {
  5245.       int momentary = suspend_momentary ();
  5246.       push_obstacks_nochange ();
  5247.       if (TREE_PERMANENT (constructor_decl))
  5248.     end_temporary_allocation ();
  5249.       make_decl_rtl (constructor_decl, constructor_asmspec,
  5250.              constructor_top_level);
  5251.       assemble_variable (constructor_decl, constructor_top_level, 0, 1);
  5252.       pop_obstacks ();
  5253.       resume_momentary (momentary);
  5254.     }
  5255.  
  5256.   if (constructor_incremental)
  5257.     {
  5258.       defer_addressed_constants ();
  5259.       constructor_subconstants_deferred = 1;
  5260.     }
  5261. }
  5262.  
  5263. /* Push down into a subobject, for initialization.
  5264.    If this is for an explicit set of braces, IMPLICIT is 0.
  5265.    If it is because the next element belongs at a lower level,
  5266.    IMPLICIT is 1.  */
  5267.  
  5268. void
  5269. push_init_level (implicit)
  5270.      int implicit;
  5271. {
  5272.   struct constructor_stack *p;
  5273.  
  5274.   /* If we've exhausted any levels that didn't have braces,
  5275.      pop them now.  */
  5276.   while (constructor_stack->implicit)
  5277.     {
  5278.       if ((TREE_CODE (constructor_type) == RECORD_TYPE
  5279.        || TREE_CODE (constructor_type) == UNION_TYPE)
  5280.       && constructor_fields == 0)
  5281.     process_init_element (pop_init_level (1));
  5282.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
  5283.            && tree_int_cst_lt (constructor_max_index, constructor_index))
  5284.     process_init_element (pop_init_level (1));
  5285.       else
  5286.     break;
  5287.     }
  5288.  
  5289.   /* Structure elements may require alignment.  Do this now
  5290.      if necessary for the subaggregate.  */
  5291.   if (constructor_incremental && constructor_type != 0
  5292.       && TREE_CODE (constructor_type) == RECORD_TYPE && constructor_fields)
  5293.     {
  5294.       /* Advance to offset of this element.  */
  5295.       if (! tree_int_cst_equal (constructor_bit_index,
  5296.                 DECL_FIELD_BITPOS (constructor_fields)))
  5297.     {
  5298.       int next = (TREE_INT_CST_LOW
  5299.               (DECL_FIELD_BITPOS (constructor_fields))
  5300.               / BITS_PER_UNIT);
  5301.       int here = (TREE_INT_CST_LOW (constructor_bit_index)
  5302.               / BITS_PER_UNIT);
  5303.  
  5304.       assemble_zeros (next - here);
  5305.     }
  5306.     }
  5307.  
  5308.   p = (struct constructor_stack *) xmalloc (sizeof (struct constructor_stack));
  5309.   p->type = constructor_type;
  5310.   p->fields = constructor_fields;
  5311.   p->index = constructor_index;
  5312.   p->range_end = constructor_range_end;
  5313.   p->max_index = constructor_max_index;
  5314.   p->unfilled_index = constructor_unfilled_index;
  5315.   p->unfilled_fields = constructor_unfilled_fields;
  5316.   p->bit_index = constructor_bit_index;
  5317.   p->elements = constructor_elements;
  5318.   p->constant = constructor_constant;
  5319.   p->simple = constructor_simple;
  5320.   p->erroneous = constructor_erroneous;
  5321.   p->pending_elts = constructor_pending_elts;
  5322.   p->depth = constructor_depth;
  5323.   p->replacement_value = 0;
  5324.   p->implicit = implicit;
  5325.   p->incremental = constructor_incremental;
  5326.   p->outer = 0;
  5327.   p->next = constructor_stack;
  5328.   constructor_stack = p;
  5329.  
  5330.   constructor_constant = 1;
  5331.   constructor_simple = 1;
  5332.   constructor_depth = SPELLING_DEPTH ();
  5333.   constructor_elements = 0;
  5334.   constructor_pending_elts = 0;
  5335.  
  5336.   /* Don't die if an entire brace-pair level is superfluous
  5337.      in the containing level.  */
  5338.   if (constructor_type == 0)
  5339.     ;
  5340.   else if (TREE_CODE (constructor_type) == RECORD_TYPE
  5341.        || TREE_CODE (constructor_type) == UNION_TYPE)
  5342.     {
  5343.       /* Don't die if there are extra init elts at the end.  */
  5344.       if (constructor_fields == 0)
  5345.     constructor_type = 0;
  5346.       else
  5347.     {
  5348.       constructor_type = TREE_TYPE (constructor_fields);
  5349.       push_member_name (constructor_fields);
  5350.       constructor_depth++;
  5351.       if (constructor_fields != constructor_unfilled_fields)
  5352.         constructor_incremental = 0;
  5353.     }
  5354.     }
  5355.   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5356.     {
  5357.       constructor_type = TREE_TYPE (constructor_type);
  5358.       push_array_bounds (TREE_INT_CST_LOW (constructor_index));
  5359.       constructor_depth++;
  5360.       if (! tree_int_cst_equal (constructor_index, constructor_unfilled_index)
  5361.       || constructor_range_end != 0)
  5362.     constructor_incremental = 0;
  5363.     }
  5364.  
  5365.   if (constructor_type == 0)
  5366.     {
  5367.       error_init ("extra brace group at end of initializer%s",
  5368.           " for `%s'", NULL);
  5369.       constructor_fields = 0;
  5370.       constructor_unfilled_fields = 0;
  5371.       return;
  5372.     }
  5373.  
  5374.   /* Turn off constructor_incremental if type is a struct with bitfields.  */
  5375.   check_init_type_bitfields (constructor_type);
  5376.  
  5377.   if (implicit && warn_missing_braces && !missing_braces_mentioned)
  5378.     {
  5379.       missing_braces_mentioned = 1;
  5380.       warning_init ("missing braces around initializer%s", " for `%s'", NULL);
  5381.     }
  5382.  
  5383.   if (TREE_CODE (constructor_type) == RECORD_TYPE
  5384.        || TREE_CODE (constructor_type) == UNION_TYPE)
  5385.     {
  5386.       constructor_fields = TYPE_FIELDS (constructor_type);
  5387.       /* Skip any nameless bit fields atthe beginning.  */
  5388.       while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
  5389.          && DECL_NAME (constructor_fields) == 0)
  5390.     constructor_fields = TREE_CHAIN (constructor_fields);
  5391.       constructor_unfilled_fields = constructor_fields;
  5392.       constructor_bit_index = copy_node (integer_zero_node);
  5393.     }
  5394.   else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5395.     {
  5396.       constructor_range_end = 0;
  5397.       if (TYPE_DOMAIN (constructor_type))
  5398.     {
  5399.       constructor_max_index
  5400.         = TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type));
  5401.       constructor_index
  5402.         = copy_node (TYPE_MIN_VALUE (TYPE_DOMAIN (constructor_type)));
  5403.     }
  5404.       else
  5405.     constructor_index = copy_node (integer_zero_node);
  5406.       constructor_unfilled_index = copy_node (constructor_index);
  5407.     }
  5408.   else
  5409.     {
  5410.       warning_init ("braces around scalar initializer%s", " for `%s'", NULL);
  5411.       constructor_fields = constructor_type;
  5412.       constructor_unfilled_fields = constructor_type;
  5413.     }
  5414. }
  5415.  
  5416. /* Don't read a struct incrementally if it has any bitfields,
  5417.    because the incremental reading code doesn't know how to
  5418.    handle bitfields yet.  */
  5419.  
  5420. static void
  5421. check_init_type_bitfields (type)
  5422.      tree type;
  5423. {
  5424.   if (TREE_CODE (type) == RECORD_TYPE)
  5425.     {
  5426.       tree tail;
  5427.       for (tail = TYPE_FIELDS (type); tail;
  5428.        tail = TREE_CHAIN (tail))
  5429.     {
  5430.       if (DECL_BIT_FIELD (tail)
  5431.           /* This catches cases like `int foo : 8;'.  */
  5432.           || DECL_MODE (tail) != TYPE_MODE (TREE_TYPE (tail)))
  5433.         {
  5434.           constructor_incremental = 0;
  5435.           break;
  5436.         }
  5437.  
  5438.       check_init_type_bitfields (TREE_TYPE (tail));
  5439.     }
  5440.     }
  5441.  
  5442.   else if (TREE_CODE (type) == ARRAY_TYPE)
  5443.     check_init_type_bitfields (TREE_TYPE (type));
  5444. }
  5445.  
  5446. /* At the end of an implicit or explicit brace level, 
  5447.    finish up that level of constructor.
  5448.    If we were outputting the elements as they are read, return 0
  5449.    from inner levels (process_init_element ignores that),
  5450.    but return error_mark_node from the outermost level
  5451.    (that's what we want to put in DECL_INITIAL).
  5452.    Otherwise, return a CONSTRUCTOR expression.  */
  5453.  
  5454. tree
  5455. pop_init_level (implicit)
  5456.      int implicit;
  5457. {
  5458.   struct constructor_stack *p;
  5459.   int size = 0;
  5460.   tree constructor = 0;
  5461.  
  5462.   if (implicit == 0)
  5463.     {
  5464.       /* When we come to an explicit close brace,
  5465.      pop any inner levels that didn't have explicit braces.  */
  5466.       while (constructor_stack->implicit)
  5467.     process_init_element (pop_init_level (1));
  5468.     }
  5469.  
  5470.   p = constructor_stack;
  5471.  
  5472.   if (constructor_type != 0)
  5473.     size = int_size_in_bytes (constructor_type);
  5474.  
  5475.   /* Now output all pending elements.  */
  5476.   output_pending_init_elements (1);
  5477.  
  5478. #if 0 /* c-parse.in warns about {}.  */
  5479.   /* In ANSI, each brace level must have at least one element.  */
  5480.   if (! implicit && pedantic
  5481.       && (TREE_CODE (constructor_type) == ARRAY_TYPE
  5482.       ? integer_zerop (constructor_unfilled_index)
  5483.       : constructor_unfilled_fields == TYPE_FIELDS (constructor_type)))
  5484.     pedwarn_init ("empty braces in initializer%s", " for `%s'", NULL);
  5485. #endif
  5486.  
  5487.   /* Pad out the end of the structure.  */
  5488.   
  5489.   if (p->replacement_value)
  5490.     {
  5491.       /* If this closes a superfluous brace pair,
  5492.      just pass out the element between them.  */
  5493.       constructor = p->replacement_value;
  5494.       /* If this is the top level thing within the initializer,
  5495.      and it's for a variable, then since we already called
  5496.      assemble_variable, we must output the value now.  */
  5497.       if (p->next == 0 && constructor_decl != 0
  5498.       && constructor_incremental)
  5499.     {
  5500.       constructor = digest_init (constructor_type, constructor,
  5501.                      require_constant_value,
  5502.                      require_constant_elements);
  5503.  
  5504.       /* If initializing an array of unknown size,
  5505.          determine the size now.  */
  5506.       if (TREE_CODE (constructor_type) == ARRAY_TYPE
  5507.           && TYPE_DOMAIN (constructor_type) == 0)
  5508.         {
  5509.           int failure;
  5510.           int momentary_p;
  5511.  
  5512.           push_obstacks_nochange ();
  5513.           if (TREE_PERMANENT (constructor_type))
  5514.         end_temporary_allocation ();
  5515.  
  5516.           momentary_p = suspend_momentary ();
  5517.  
  5518.           /* We shouldn't have an incomplete array type within
  5519.          some other type.  */
  5520.           if (constructor_stack->next)
  5521.         abort ();
  5522.  
  5523.           failure
  5524.         = complete_array_type (constructor_type,
  5525.                        constructor, 0);
  5526.           if (failure)
  5527.         abort ();
  5528.  
  5529.           size = int_size_in_bytes (constructor_type);
  5530.           resume_momentary (momentary_p);
  5531.           pop_obstacks ();
  5532.         }
  5533.  
  5534.       output_constant (constructor, size);
  5535.     }
  5536.     }
  5537.   else if (constructor_type == 0)
  5538.     ;
  5539.   else if (TREE_CODE (constructor_type) != RECORD_TYPE
  5540.        && TREE_CODE (constructor_type) != UNION_TYPE
  5541.        && TREE_CODE (constructor_type) != ARRAY_TYPE
  5542.        && ! constructor_incremental)
  5543.     {
  5544.       /* A nonincremental scalar initializer--just return
  5545.      the element, after verifying there is just one.  */
  5546.       if (constructor_elements == 0)
  5547.     {
  5548.       error_init ("empty scalar initializer%s",
  5549.               " for `%s'", NULL);
  5550.       constructor = error_mark_node;
  5551.     }
  5552.       else if (TREE_CHAIN (constructor_elements) != 0)
  5553.     {
  5554.       error_init ("extra elements in scalar initializer%s",
  5555.               " for `%s'", NULL);
  5556.       constructor = TREE_VALUE (constructor_elements);
  5557.     }
  5558.       else
  5559.     constructor = TREE_VALUE (constructor_elements);
  5560.     }
  5561.   else if (! constructor_incremental)
  5562.     {
  5563.       if (constructor_erroneous)
  5564.     constructor = error_mark_node;
  5565.       else
  5566.     {
  5567.       int momentary = suspend_momentary ();
  5568.  
  5569.       constructor = build (CONSTRUCTOR, constructor_type, NULL_TREE,
  5570.                    nreverse (constructor_elements));
  5571.       if (constructor_constant)
  5572.         TREE_CONSTANT (constructor) = 1;
  5573.       if (constructor_constant && constructor_simple)
  5574.         TREE_STATIC (constructor) = 1;
  5575.  
  5576.       resume_momentary (momentary);
  5577.     }
  5578.     }
  5579.   else
  5580.     {
  5581.       tree filled;
  5582.       int momentary = suspend_momentary ();
  5583.  
  5584.       if (TREE_CODE (constructor_type) == RECORD_TYPE
  5585.       || TREE_CODE (constructor_type) == UNION_TYPE)
  5586.     {
  5587.       /* Find the offset of the end of that field.  */
  5588.       filled = size_binop (CEIL_DIV_EXPR,
  5589.                    constructor_bit_index,
  5590.                    size_int (BITS_PER_UNIT));
  5591.     }
  5592.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5593.     {
  5594.       /* If initializing an array of unknown size,
  5595.          determine the size now.  */
  5596.       if (TREE_CODE (constructor_type) == ARRAY_TYPE
  5597.           && TYPE_DOMAIN (constructor_type) == 0)
  5598.         {
  5599.           tree maxindex
  5600.         = size_binop (MINUS_EXPR,
  5601.                   constructor_unfilled_index,
  5602.                   integer_one_node);
  5603.  
  5604.           push_obstacks_nochange ();
  5605.           if (TREE_PERMANENT (constructor_type))
  5606.         end_temporary_allocation ();
  5607.           maxindex = copy_node (maxindex);
  5608.           TYPE_DOMAIN (constructor_type) = build_index_type (maxindex);
  5609.           TREE_TYPE (maxindex) = TYPE_DOMAIN (constructor_type);
  5610.  
  5611.           /* TYPE_MAX_VALUE is always one less than the number of elements
  5612.          in the array, because we start counting at zero.  Therefore,
  5613.          warn only if the value is less than zero.  */
  5614.           if (pedantic
  5615.           && (tree_int_cst_sgn (TYPE_MAX_VALUE (TYPE_DOMAIN (constructor_type)))
  5616.               < 0))
  5617.         error_with_decl (constructor_decl,
  5618.                  "zero or negative array size `%s'");
  5619.           layout_type (constructor_type);
  5620.           size = int_size_in_bytes (constructor_type);
  5621.           pop_obstacks ();
  5622.         }
  5623.  
  5624.       filled = size_binop (MULT_EXPR, constructor_unfilled_index,
  5625.                    size_in_bytes (TREE_TYPE (constructor_type)));
  5626.     }
  5627.       else
  5628.     filled = 0;
  5629.  
  5630.       if (filled != 0)
  5631.     assemble_zeros (size - TREE_INT_CST_LOW (filled));
  5632.  
  5633.       resume_momentary (momentary);
  5634.     }
  5635.  
  5636.       
  5637.   constructor_type = p->type;
  5638.   constructor_fields = p->fields;
  5639.   constructor_index = p->index;
  5640.   constructor_range_end = p->range_end;
  5641.   constructor_max_index = p->max_index;
  5642.   constructor_unfilled_index = p->unfilled_index;
  5643.   constructor_unfilled_fields = p->unfilled_fields;
  5644.   constructor_bit_index = p->bit_index;
  5645.   constructor_elements = p->elements;
  5646.   constructor_constant = p->constant;
  5647.   constructor_simple = p->simple;
  5648.   constructor_erroneous = p->erroneous;
  5649.   constructor_pending_elts = p->pending_elts;
  5650.   constructor_depth = p->depth;
  5651.   constructor_incremental = p->incremental;
  5652.   RESTORE_SPELLING_DEPTH (constructor_depth);
  5653.  
  5654.   constructor_stack = p->next;
  5655.   free (p);
  5656.  
  5657.   if (constructor == 0)
  5658.     {
  5659.       if (constructor_stack == 0)
  5660.     return error_mark_node;
  5661.       return NULL_TREE;
  5662.     }
  5663.   return constructor;
  5664. }
  5665.  
  5666. /* Within an array initializer, specify the next index to be initialized.
  5667.    FIRST is that index.  If LAST is nonzero, then initialize a range
  5668.    of indices, running from FIRST through LAST.  */
  5669.  
  5670. void
  5671. set_init_index (first, last)
  5672.      tree first, last;
  5673. {
  5674.   while ((TREE_CODE (first) == NOP_EXPR
  5675.       || TREE_CODE (first) == CONVERT_EXPR
  5676.       || TREE_CODE (first) == NON_LVALUE_EXPR)
  5677.      && (TYPE_MODE (TREE_TYPE (first))
  5678.          == TYPE_MODE (TREE_TYPE (TREE_OPERAND (first, 0)))))
  5679.     (first) = TREE_OPERAND (first, 0);
  5680.   if (last)
  5681.     while ((TREE_CODE (last) == NOP_EXPR
  5682.         || TREE_CODE (last) == CONVERT_EXPR
  5683.         || TREE_CODE (last) == NON_LVALUE_EXPR)
  5684.        && (TYPE_MODE (TREE_TYPE (last))
  5685.            == TYPE_MODE (TREE_TYPE (TREE_OPERAND (last, 0)))))
  5686.       (last) = TREE_OPERAND (last, 0);
  5687.  
  5688.   if (TREE_CODE (first) != INTEGER_CST)
  5689.     error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
  5690.   else if (last != 0 && TREE_CODE (last) != INTEGER_CST)
  5691.     error_init ("nonconstant array index in initializer%s", " for `%s'", NULL);
  5692.   else if (tree_int_cst_lt (first, constructor_unfilled_index))
  5693.     error_init ("duplicate array index in initializer%s", " for `%s'", NULL);
  5694.   else
  5695.     {
  5696.       TREE_INT_CST_LOW (constructor_index)
  5697.     = TREE_INT_CST_LOW (first);
  5698.       TREE_INT_CST_HIGH (constructor_index)
  5699.     = TREE_INT_CST_HIGH (first);
  5700.  
  5701.       if (last != 0 && tree_int_cst_lt (last, first))
  5702.     error_init ("empty index range in initializer%s", " for `%s'", NULL);
  5703.       else
  5704.     {
  5705.       if (pedantic)
  5706.         pedwarn ("ANSI C forbids specifying element to initialize");
  5707.       constructor_range_end = last;
  5708.     }
  5709.     }
  5710. }
  5711.  
  5712. /* Within a struct initializer, specify the next field to be initialized.  */
  5713.  
  5714. void
  5715. set_init_label (fieldname)
  5716.      tree fieldname;
  5717. {
  5718.   tree tail;
  5719.   int passed = 0;
  5720.  
  5721.   for (tail = TYPE_FIELDS (constructor_type); tail;
  5722.        tail = TREE_CHAIN (tail))
  5723.     {
  5724.       if (tail == constructor_unfilled_fields)
  5725.     passed = 1;
  5726.       if (DECL_NAME (tail) == fieldname)
  5727.     break;
  5728.     }
  5729.  
  5730.   if (tail == 0)
  5731.     error ("unknown field `%s' specified in initializer",
  5732.        IDENTIFIER_POINTER (fieldname));
  5733.   else if (!passed)
  5734.     error ("field `%s' already initialized",
  5735.        IDENTIFIER_POINTER (fieldname));
  5736.   else
  5737.     {
  5738.       constructor_fields = tail;
  5739.       if (pedantic)
  5740.     pedwarn ("ANSI C forbids specifying structure member to initialize");
  5741.     }
  5742. }
  5743.  
  5744. /* "Output" the next constructor element.
  5745.    At top level, really output it to assembler code now.
  5746.    Otherwise, collect it in a list from which we will make a CONSTRUCTOR.
  5747.    TYPE is the data type that the containing data type wants here.
  5748.    FIELD is the field (a FIELD_DECL) or the index that this element fills.
  5749.  
  5750.    PENDING if non-nil means output pending elements that belong
  5751.    right after this element.  (PENDING is normally 1;
  5752.    it is 0 while outputting pending elements, to avoid recursion.)  */
  5753.  
  5754. static void
  5755. output_init_element (value, type, field, pending)
  5756.      tree value, type, field;
  5757.      int pending;
  5758. {
  5759.   int duplicate = 0;
  5760.  
  5761.   if (TREE_CODE (TREE_TYPE (value)) == FUNCTION_TYPE
  5762.       || (TREE_CODE (TREE_TYPE (value)) == ARRAY_TYPE
  5763.       && !(TREE_CODE (value) == STRING_CST
  5764.            && TREE_CODE (type) == ARRAY_TYPE
  5765.            && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
  5766.       && !comptypes (TYPE_MAIN_VARIANT (TREE_TYPE (value)),
  5767.              TYPE_MAIN_VARIANT (type))))
  5768.     value = default_conversion (value);
  5769.  
  5770.   if (value == error_mark_node)
  5771.     constructor_erroneous = 1;
  5772.   else if (!TREE_CONSTANT (value))
  5773.     constructor_constant = 0;
  5774.   else if (initializer_constant_valid_p (value, TREE_TYPE (value)) == 0
  5775.        || ((TREE_CODE (constructor_type) == RECORD_TYPE
  5776.         || TREE_CODE (constructor_type) == UNION_TYPE)
  5777.            && DECL_BIT_FIELD (field) && TREE_CODE (value) != INTEGER_CST))
  5778.     constructor_simple = 0;
  5779.  
  5780.   if (require_constant_value && ! TREE_CONSTANT (value))
  5781.     {
  5782.       error_init ("initializer element%s is not constant",
  5783.           " for `%s'", NULL);
  5784.       value = error_mark_node;
  5785.     }
  5786.   else if (require_constant_elements
  5787.        && initializer_constant_valid_p (value, TREE_TYPE (value)) == 0)
  5788.     {
  5789.       error_init ("initializer element%s is not computable at load time",
  5790.           " for `%s'", NULL);
  5791.       value = error_mark_node;
  5792.     }
  5793.  
  5794.   /* If this element duplicates one on constructor_pending_elts,
  5795.      print a message and ignore it.  Don't do this when we're
  5796.      processing elements taken off constructor_pending_elts,
  5797.      because we'd always get spurious errors.  */
  5798.   if (pending)
  5799.     {
  5800.       if (TREE_CODE (constructor_type) == RECORD_TYPE
  5801.       || TREE_CODE (constructor_type) == UNION_TYPE)
  5802.     {
  5803.       if (purpose_member (field, constructor_pending_elts))
  5804.         {
  5805.           error_init ("duplicate initializer%s", " for `%s'", NULL);
  5806.           duplicate = 1;
  5807.         }
  5808.     }
  5809.       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5810.     {
  5811.       tree tail;
  5812.       for (tail = constructor_pending_elts; tail;
  5813.            tail = TREE_CHAIN (tail))
  5814.         if (TREE_PURPOSE (tail) != 0
  5815.         && TREE_CODE (TREE_PURPOSE (tail)) == INTEGER_CST
  5816.         && tree_int_cst_equal (TREE_PURPOSE (tail), constructor_index))
  5817.           break;
  5818.  
  5819.       if (tail != 0)
  5820.         {
  5821.           error_init ("duplicate initializer%s", " for `%s'", NULL);
  5822.           duplicate = 1;
  5823.         }
  5824.     }
  5825.     }
  5826.  
  5827.   /* If this element doesn't come next in sequence,
  5828.      put it on constructor_pending_elts.  */
  5829.   if (TREE_CODE (constructor_type) == ARRAY_TYPE
  5830.       && !tree_int_cst_equal (field, constructor_unfilled_index))
  5831.     {
  5832.       if (! duplicate)
  5833.     /* The copy_node is needed in case field is actually
  5834.        constructor_index, which is modified in place.  */
  5835.     constructor_pending_elts
  5836.       = tree_cons (copy_node (field),
  5837.                digest_init (type, value, require_constant_value, 
  5838.                     require_constant_elements),
  5839.                constructor_pending_elts);
  5840.     }
  5841.   else if (TREE_CODE (constructor_type) == RECORD_TYPE
  5842.        && field != constructor_unfilled_fields)
  5843.     {
  5844.       /* We do this for records but not for unions.  In a union,
  5845.      no matter which field is specified, it can be initialized
  5846.      right away since it starts at the beginning of the union.  */
  5847.       if (!duplicate)
  5848.     constructor_pending_elts
  5849.       = tree_cons (field,
  5850.                digest_init (type, value, require_constant_value, 
  5851.                     require_constant_elements),
  5852.                constructor_pending_elts);
  5853.     }
  5854.   else
  5855.     {
  5856.       /* Otherwise, output this element either to
  5857.      constructor_elements or to the assembler file.  */
  5858.  
  5859.       if (!duplicate)
  5860.     {
  5861.       if (! constructor_incremental)
  5862.         {
  5863.           if (field && TREE_CODE (field) == INTEGER_CST)
  5864.         field = copy_node (field);
  5865.           constructor_elements
  5866.         = tree_cons (field, digest_init (type, value,
  5867.                          require_constant_value, 
  5868.                          require_constant_elements),
  5869.                  constructor_elements);
  5870.         }
  5871.       else
  5872.         {
  5873.           /* Structure elements may require alignment.
  5874.          Do this, if necessary.  */
  5875.           if (TREE_CODE (constructor_type) == RECORD_TYPE)
  5876.         {
  5877.           /* Advance to offset of this element.  */
  5878.           if (! tree_int_cst_equal (constructor_bit_index,
  5879.                         DECL_FIELD_BITPOS (field)))
  5880.             {
  5881.               int next = (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
  5882.                   / BITS_PER_UNIT);
  5883.               int here = (TREE_INT_CST_LOW (constructor_bit_index)
  5884.                   / BITS_PER_UNIT);
  5885.  
  5886.               assemble_zeros (next - here);
  5887.             }
  5888.         }
  5889.           output_constant (digest_init (type, value,
  5890.                         require_constant_value,
  5891.                         require_constant_elements),
  5892.                    int_size_in_bytes (type));
  5893.  
  5894.           /* For a record or union,
  5895.          keep track of end position of last field.  */
  5896.           if (TREE_CODE (constructor_type) == RECORD_TYPE
  5897.           || TREE_CODE (constructor_type) == UNION_TYPE)
  5898.         {
  5899.           tree temp = size_binop (PLUS_EXPR, DECL_FIELD_BITPOS (field),
  5900.                       DECL_SIZE (field));
  5901.           TREE_INT_CST_LOW (constructor_bit_index)
  5902.             = TREE_INT_CST_LOW (temp);
  5903.           TREE_INT_CST_HIGH (constructor_bit_index)
  5904.             = TREE_INT_CST_HIGH (temp);
  5905.         }
  5906.         }
  5907.     }
  5908.  
  5909.       /* Advance the variable that indicates sequential elements output.  */
  5910.       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5911.     {
  5912.       tree tem = size_binop (PLUS_EXPR, constructor_unfilled_index,
  5913.                  integer_one_node);
  5914.       TREE_INT_CST_LOW (constructor_unfilled_index)
  5915.         = TREE_INT_CST_LOW (tem);
  5916.       TREE_INT_CST_HIGH (constructor_unfilled_index)
  5917.         = TREE_INT_CST_HIGH (tem);
  5918.     }
  5919.       else if (TREE_CODE (constructor_type) == RECORD_TYPE)
  5920.     constructor_unfilled_fields = TREE_CHAIN (constructor_unfilled_fields);
  5921.       else if (TREE_CODE (constructor_type) == UNION_TYPE)
  5922.     constructor_unfilled_fields = 0;
  5923.  
  5924.       /* Now output any pending elements which have become next.  */
  5925.       if (pending)
  5926.     output_pending_init_elements (0);
  5927.     }
  5928. }
  5929.  
  5930. /* Output any pending elements which have become next.
  5931.    As we output elements, constructor_unfilled_{fields,index}
  5932.    advances, which may cause other elements to become next;
  5933.    if so, they too are output.
  5934.  
  5935.    If ALL is 0, we return when there are
  5936.    no more pending elements to output now.
  5937.  
  5938.    If ALL is 1, we output space as necessary so that
  5939.    we can output all the pending elements.  */
  5940.  
  5941. static void
  5942. output_pending_init_elements (all)
  5943.      int all;
  5944. {
  5945.   tree tail;
  5946.   tree next;
  5947.  
  5948.  retry:
  5949.  
  5950.   /* Look thru the whole pending list.
  5951.      If we find an element that should be output now,
  5952.      output it.  Otherwise, set NEXT to the element
  5953.      that comes first among those still pending.  */
  5954.      
  5955.   next = 0;
  5956.   for (tail = constructor_pending_elts; tail;
  5957.        tail = TREE_CHAIN (tail))
  5958.     {
  5959.       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  5960.     {
  5961.       if (tree_int_cst_equal (TREE_PURPOSE (tail),
  5962.                   constructor_unfilled_index))
  5963.         {
  5964.           output_init_element (TREE_VALUE (tail),
  5965.                    TREE_TYPE (constructor_type),
  5966.                    constructor_unfilled_index, 0);
  5967.           goto retry;
  5968.         }
  5969.       else if (tree_int_cst_lt (TREE_PURPOSE (tail),
  5970.                     constructor_unfilled_index))
  5971.         ;
  5972.       else if (next == 0
  5973.            || tree_int_cst_lt (TREE_PURPOSE (tail), next))
  5974.         next = TREE_PURPOSE (tail);
  5975.     }
  5976.       else if (TREE_CODE (constructor_type) == RECORD_TYPE
  5977.            || TREE_CODE (constructor_type) == UNION_TYPE)
  5978.     {
  5979.       if (TREE_PURPOSE (tail) == constructor_unfilled_fields)
  5980.         {
  5981.           output_init_element (TREE_VALUE (tail),
  5982.                    TREE_TYPE (constructor_unfilled_fields),
  5983.                    constructor_unfilled_fields,
  5984.                    0);
  5985.           goto retry;
  5986.         }
  5987.       else if (constructor_unfilled_fields == 0
  5988.            || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)),
  5989.                        DECL_FIELD_BITPOS (constructor_unfilled_fields)))
  5990.         ;
  5991.       else if (next == 0
  5992.            || tree_int_cst_lt (DECL_FIELD_BITPOS (TREE_PURPOSE (tail)),
  5993.                        DECL_FIELD_BITPOS (next)))
  5994.         next = TREE_PURPOSE (tail);
  5995.     }
  5996.     }
  5997.  
  5998.   /* Ordinarily return, but not if we want to output all
  5999.      and there are elements left.  */
  6000.   if (! (all && next != 0))
  6001.     return;
  6002.  
  6003.   /* Generate space up to the position of NEXT.  */
  6004.   if (constructor_incremental)
  6005.     {
  6006.       tree filled;
  6007.       tree nextpos_tree = size_int (0);
  6008.  
  6009.       if (TREE_CODE (constructor_type) == RECORD_TYPE
  6010.       || TREE_CODE (constructor_type) == UNION_TYPE)
  6011.     {
  6012.       /* Find the last field written out, if any.  */
  6013.       for (tail = TYPE_FIELDS (constructor_type); tail;
  6014.            tail = TREE_CHAIN (tail))
  6015.         if (TREE_CHAIN (tail) == constructor_unfilled_fields)
  6016.           break;
  6017.  
  6018.       if (tail)
  6019.         /* Find the offset of the end of that field.  */
  6020.         filled = size_binop (CEIL_DIV_EXPR,
  6021.                  size_binop (PLUS_EXPR,
  6022.                          DECL_FIELD_BITPOS (tail),
  6023.                          DECL_SIZE (tail)),
  6024.                  size_int (BITS_PER_UNIT));
  6025.       else
  6026.         filled = size_int (0);
  6027.  
  6028.       nextpos_tree = size_binop (CEIL_DIV_EXPR,
  6029.                      DECL_FIELD_BITPOS (next),
  6030.                      size_int (BITS_PER_UNIT));
  6031.  
  6032.       TREE_INT_CST_HIGH (constructor_bit_index)
  6033.         = TREE_INT_CST_HIGH (DECL_FIELD_BITPOS (next));
  6034.       TREE_INT_CST_LOW (constructor_bit_index)
  6035.         = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (next));
  6036.       constructor_unfilled_fields = next;
  6037.     }
  6038.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  6039.     {
  6040.       filled = size_binop (MULT_EXPR, constructor_unfilled_index,
  6041.                    size_in_bytes (TREE_TYPE (constructor_type)));
  6042.       nextpos_tree
  6043.         = size_binop (MULT_EXPR, next,
  6044.               size_in_bytes (TREE_TYPE (constructor_type)));
  6045.       TREE_INT_CST_LOW (constructor_unfilled_index)
  6046.         = TREE_INT_CST_LOW (next);
  6047.       TREE_INT_CST_HIGH (constructor_unfilled_index)
  6048.         = TREE_INT_CST_HIGH (next);
  6049.     }
  6050.       else
  6051.     filled = 0;
  6052.  
  6053.       if (filled)
  6054.     {
  6055.       int nextpos = TREE_INT_CST_LOW (nextpos_tree);
  6056.  
  6057.       assemble_zeros (nextpos - TREE_INT_CST_LOW (filled));
  6058.     }
  6059.     }
  6060.   else
  6061.     {
  6062.       /* If it's not incremental, just skip over the gap,
  6063.      so that after jumping to retry we will output the next
  6064.      successive element.  */
  6065.       if (TREE_CODE (constructor_type) == RECORD_TYPE
  6066.       || TREE_CODE (constructor_type) == UNION_TYPE)
  6067.     constructor_unfilled_fields = next;
  6068.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  6069.     {
  6070.       TREE_INT_CST_LOW (constructor_unfilled_index)
  6071.         = TREE_INT_CST_LOW (next);
  6072.       TREE_INT_CST_HIGH (constructor_unfilled_index)
  6073.         = TREE_INT_CST_HIGH (next);
  6074.     }
  6075.     }
  6076.  
  6077.   goto retry;
  6078. }
  6079.  
  6080. /* Add one non-braced element to the current constructor level.
  6081.    This adjusts the current position within the constructor's type.
  6082.    This may also start or terminate implicit levels
  6083.    to handle a partly-braced initializer.
  6084.  
  6085.    Once this has found the correct level for the new element,
  6086.    it calls output_init_element.
  6087.  
  6088.    Note: if we are incrementally outputting this constructor,
  6089.    this function may be called with a null argument
  6090.    representing a sub-constructor that was already incrementally output.
  6091.    When that happens, we output nothing, but we do the bookkeeping
  6092.    to skip past that element of the current constructor.  */
  6093.  
  6094. void
  6095. process_init_element (value)
  6096.      tree value;
  6097. {
  6098.   tree orig_value = value;
  6099.   int string_flag = value != 0 && TREE_CODE (value) == STRING_CST;
  6100.  
  6101.   /* Handle superfluous braces around string cst as in
  6102.      char x[] = {"foo"}; */
  6103.   if (string_flag
  6104.       && constructor_type
  6105.       && TREE_CODE (constructor_type) == ARRAY_TYPE
  6106.       && TREE_CODE (TREE_TYPE (constructor_type)) == INTEGER_TYPE
  6107.       && integer_zerop (constructor_unfilled_index))
  6108.     {
  6109.       constructor_stack->replacement_value = value;
  6110.       return;
  6111.     }
  6112.  
  6113.   if (constructor_stack->replacement_value != 0)
  6114.     {
  6115.       error_init ("excess elements in struct initializer%s",
  6116.           " after `%s'", NULL_PTR);
  6117.       return;
  6118.     }
  6119.  
  6120.   /* Ignore elements of a brace group if it is entirely superfluous
  6121.      and has already been diagnosed.  */
  6122.   if (constructor_type == 0)
  6123.     return;
  6124.  
  6125.   /* If we've exhausted any levels that didn't have braces,
  6126.      pop them now.  */
  6127.   while (constructor_stack->implicit)
  6128.     {
  6129.       if ((TREE_CODE (constructor_type) == RECORD_TYPE
  6130.        || TREE_CODE (constructor_type) == UNION_TYPE)
  6131.       && constructor_fields == 0)
  6132.     process_init_element (pop_init_level (1));
  6133.       else if (TREE_CODE (constructor_type) == ARRAY_TYPE
  6134.            && tree_int_cst_lt (constructor_max_index, constructor_index))
  6135.     process_init_element (pop_init_level (1));
  6136.       else
  6137.     break;
  6138.     }
  6139.  
  6140.   while (1)
  6141.     {
  6142.       if (TREE_CODE (constructor_type) == RECORD_TYPE)
  6143.     {
  6144.       tree fieldtype;
  6145.       enum tree_code fieldcode;
  6146.  
  6147.       if (constructor_fields == 0)
  6148.         {
  6149.           pedwarn_init ("excess elements in struct initializer%s",
  6150.                 " after `%s'", NULL_PTR);
  6151.           break;
  6152.         }
  6153.  
  6154.       fieldtype = TREE_TYPE (constructor_fields);
  6155.       if (fieldtype != error_mark_node)
  6156.         fieldtype = TYPE_MAIN_VARIANT (fieldtype);
  6157.       fieldcode = TREE_CODE (fieldtype);
  6158.  
  6159.       /* Accept a string constant to initialize a subarray.  */
  6160.       if (value != 0
  6161.           && fieldcode == ARRAY_TYPE
  6162.           && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
  6163.           && string_flag)
  6164.         value = orig_value;
  6165.       /* Otherwise, if we have come to a subaggregate,
  6166.          and we don't have an element of its type, push into it.  */
  6167.       else if (value != 0 && !constructor_no_implicit
  6168.            && value != error_mark_node
  6169.            && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
  6170.            && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
  6171.                || fieldcode == UNION_TYPE))
  6172.         {
  6173.           push_init_level (1);
  6174.           continue;
  6175.         }
  6176.  
  6177.       if (value)
  6178.         {
  6179.           push_member_name (constructor_fields);
  6180.           output_init_element (value, fieldtype, constructor_fields, 1);
  6181.           RESTORE_SPELLING_DEPTH (constructor_depth);
  6182.         }
  6183.       else
  6184.         /* Do the bookkeeping for an element that was
  6185.            directly output as a constructor.  */
  6186.         {
  6187.           /* For a record, keep track of end position of last field.  */
  6188.           tree temp = size_binop (PLUS_EXPR,
  6189.                       DECL_FIELD_BITPOS (constructor_fields),
  6190.                       DECL_SIZE (constructor_fields));
  6191.           TREE_INT_CST_LOW (constructor_bit_index)
  6192.         = TREE_INT_CST_LOW (temp);
  6193.           TREE_INT_CST_HIGH (constructor_bit_index)
  6194.         = TREE_INT_CST_HIGH (temp);
  6195.  
  6196.           constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
  6197.         }
  6198.  
  6199.       constructor_fields = TREE_CHAIN (constructor_fields);
  6200.       /* Skip any nameless bit fields atthe beginning.  */
  6201.       while (constructor_fields != 0 && DECL_BIT_FIELD (constructor_fields)
  6202.          && DECL_NAME (constructor_fields) == 0)
  6203.         constructor_fields = TREE_CHAIN (constructor_fields);
  6204.       break;
  6205.     }
  6206.       if (TREE_CODE (constructor_type) == UNION_TYPE)
  6207.     {
  6208.       tree fieldtype;
  6209.       enum tree_code fieldcode;
  6210.  
  6211.       if (constructor_fields == 0)
  6212.         {
  6213.           pedwarn_init ("excess elements in union initializer%s",
  6214.                 " after `%s'", NULL_PTR);
  6215.           break;
  6216.         }
  6217.  
  6218.       fieldtype = TREE_TYPE (constructor_fields);
  6219.       if (fieldtype != error_mark_node)
  6220.         fieldtype = TYPE_MAIN_VARIANT (fieldtype);
  6221.       fieldcode = TREE_CODE (fieldtype);
  6222.  
  6223.       /* Accept a string constant to initialize a subarray.  */
  6224.       if (value != 0
  6225.           && fieldcode == ARRAY_TYPE
  6226.           && TREE_CODE (TREE_TYPE (fieldtype)) == INTEGER_TYPE
  6227.           && string_flag)
  6228.         value = orig_value;
  6229.       /* Otherwise, if we have come to a subaggregate,
  6230.          and we don't have an element of its type, push into it.  */
  6231.       else if (value != 0 && !constructor_no_implicit
  6232.            && value != error_mark_node
  6233.            && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != fieldtype
  6234.            && (fieldcode == RECORD_TYPE || fieldcode == ARRAY_TYPE
  6235.                || fieldcode == UNION_TYPE))
  6236.         {
  6237.           push_init_level (1);
  6238.           continue;
  6239.         }
  6240.  
  6241.       if (value)
  6242.         {
  6243.           push_member_name (constructor_fields);
  6244.           output_init_element (value, fieldtype, constructor_fields, 1);
  6245.           RESTORE_SPELLING_DEPTH (constructor_depth);
  6246.         }
  6247.       else
  6248.         /* Do the bookkeeping for an element that was
  6249.            directly output as a constructor.  */
  6250.         {
  6251.           TREE_INT_CST_LOW (constructor_bit_index)
  6252.         = TREE_INT_CST_LOW (DECL_SIZE (constructor_fields));
  6253.           TREE_INT_CST_HIGH (constructor_bit_index)
  6254.         = TREE_INT_CST_HIGH (DECL_SIZE (constructor_fields));
  6255.  
  6256.           constructor_unfilled_fields = TREE_CHAIN (constructor_fields);
  6257.         }
  6258.  
  6259.       constructor_fields = 0;
  6260.       break;
  6261.     }
  6262.       if (TREE_CODE (constructor_type) == ARRAY_TYPE)
  6263.     {
  6264.       tree elttype = TYPE_MAIN_VARIANT (TREE_TYPE (constructor_type));
  6265.       enum tree_code eltcode = TREE_CODE (elttype);
  6266.  
  6267.       /* Accept a string constant to initialize a subarray.  */
  6268.       if (value != 0
  6269.           && eltcode == ARRAY_TYPE
  6270.           && TREE_CODE (TREE_TYPE (elttype)) == INTEGER_TYPE
  6271.           && string_flag)
  6272.         value = orig_value;
  6273.       /* Otherwise, if we have come to a subaggregate,
  6274.          and we don't have an element of its type, push into it.  */
  6275.       else if (value != 0 && !constructor_no_implicit
  6276.            && value != error_mark_node
  6277.            && TYPE_MAIN_VARIANT (TREE_TYPE (value)) != elttype
  6278.            && (eltcode == RECORD_TYPE || eltcode == ARRAY_TYPE
  6279.                || eltcode == UNION_TYPE))
  6280.         {
  6281.           push_init_level (1);
  6282.           continue;
  6283.         }
  6284.  
  6285.       if (constructor_max_index != 0
  6286.           && tree_int_cst_lt (constructor_max_index, constructor_index))
  6287.         {
  6288.           pedwarn_init ("excess elements in array initializer%s",
  6289.                 " after `%s'", NULL_PTR);
  6290.           break;
  6291.         }
  6292.  
  6293.       /* In the case of [LO .. HI] = VALUE, only evaluate VALUE once. */
  6294.       if (constructor_range_end)
  6295.         value = save_expr (value);
  6296.  
  6297.       /* Now output the actual element.
  6298.          Ordinarily, output once.
  6299.          If there is a range, repeat it till we advance past the range.  */
  6300.       do
  6301.         {
  6302.           tree tem;
  6303.  
  6304.           if (value)
  6305.         {
  6306.           push_array_bounds (TREE_INT_CST_LOW (constructor_index));
  6307.           output_init_element (value, elttype, constructor_index, 1);
  6308.           RESTORE_SPELLING_DEPTH (constructor_depth);
  6309.         }
  6310.  
  6311.           tem = size_binop (PLUS_EXPR, constructor_index,
  6312.                 integer_one_node);
  6313.           TREE_INT_CST_LOW (constructor_index)
  6314.         = TREE_INT_CST_LOW (tem);
  6315.           TREE_INT_CST_HIGH (constructor_index)
  6316.         = TREE_INT_CST_HIGH (tem);
  6317.  
  6318.           if (!value)
  6319.         /* If we are doing the bookkeeping for an element that was
  6320.            directly output as a constructor,
  6321.            we must update constructor_unfilled_index.  */
  6322.         {
  6323.           TREE_INT_CST_LOW (constructor_unfilled_index)
  6324.             = TREE_INT_CST_LOW (constructor_index);
  6325.           TREE_INT_CST_HIGH (constructor_unfilled_index)
  6326.             = TREE_INT_CST_HIGH (constructor_index);
  6327.         }
  6328.         }
  6329.       while (! (constructor_range_end == 0
  6330.             || tree_int_cst_lt (constructor_range_end,
  6331.                     constructor_index)));
  6332.  
  6333.       break;
  6334.     }
  6335.  
  6336.       /* Handle the sole element allowed in a braced initializer
  6337.      for a scalar variable.  */
  6338.       if (constructor_fields == 0)
  6339.     {
  6340.       pedwarn_init ("excess elements in scalar initializer%s",
  6341.             " after `%s'", NULL_PTR);
  6342.       break;
  6343.     }
  6344.  
  6345.       if (value)
  6346.     output_init_element (value, constructor_type, NULL_TREE, 1);
  6347.       constructor_fields = 0;
  6348.       break;
  6349.     }
  6350.  
  6351.   /* If the (lexically) previous elments are not now saved,
  6352.      we can discard the storage for them.  */
  6353.   if (constructor_incremental && constructor_pending_elts == 0 && value != 0
  6354.       && constructor_stack == 0)
  6355.     clear_momentary ();
  6356. }
  6357.  
  6358. /* Expand an ASM statement with operands, handling output operands
  6359.    that are not variables or INDIRECT_REFS by transforming such
  6360.    cases into cases that expand_asm_operands can handle.
  6361.  
  6362.    Arguments are same as for expand_asm_operands.  */
  6363.  
  6364. void
  6365. c_expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
  6366.      tree string, outputs, inputs, clobbers;
  6367.      int vol;
  6368.      char *filename;
  6369.      int line;
  6370. {
  6371.   int noutputs = list_length (outputs);
  6372.   register int i;
  6373.   /* o[I] is the place that output number I should be written.  */
  6374.   register tree *o = (tree *) alloca (noutputs * sizeof (tree));
  6375.   register tree tail;
  6376.  
  6377.   if (TREE_CODE (string) == ADDR_EXPR)
  6378.     string = TREE_OPERAND (string, 0);
  6379.   if (TREE_CODE (string) != STRING_CST)
  6380.     {
  6381.       error ("asm template is not a string constant");
  6382.       return;
  6383.     }
  6384.  
  6385.   /* Record the contents of OUTPUTS before it is modified.  */
  6386.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  6387.     o[i] = TREE_VALUE (tail);
  6388.  
  6389.   /* Perform default conversions on array and function inputs.  */
  6390.   /* Don't do this for other types--
  6391.      it would screw up operands expected to be in memory.  */
  6392.   for (i = 0, tail = inputs; tail; tail = TREE_CHAIN (tail), i++)
  6393.     if (TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == ARRAY_TYPE
  6394.     || TREE_CODE (TREE_TYPE (TREE_VALUE (tail))) == FUNCTION_TYPE)
  6395.       TREE_VALUE (tail) = default_conversion (TREE_VALUE (tail));
  6396.  
  6397.   /* Generate the ASM_OPERANDS insn;
  6398.      store into the TREE_VALUEs of OUTPUTS some trees for
  6399.      where the values were actually stored.  */
  6400.   expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line);
  6401.  
  6402.   /* Copy all the intermediate outputs into the specified outputs.  */
  6403.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  6404.     {
  6405.       if (o[i] != TREE_VALUE (tail))
  6406.     {
  6407.       expand_expr (build_modify_expr (o[i], NOP_EXPR, TREE_VALUE (tail)),
  6408.                0, VOIDmode, 0);
  6409.       free_temp_slots ();
  6410.     }
  6411.       /* Detect modification of read-only values.
  6412.      (Otherwise done by build_modify_expr.)  */
  6413.       else
  6414.     {
  6415.       tree type = TREE_TYPE (o[i]);
  6416.       if (TYPE_READONLY (type)
  6417.           || ((TREE_CODE (type) == RECORD_TYPE
  6418.            || TREE_CODE (type) == UNION_TYPE)
  6419.           && C_TYPE_FIELDS_READONLY (type)))
  6420.         readonly_warning (o[i], "modification by `asm'");
  6421.     }
  6422.     }
  6423.  
  6424.   /* Those MODIFY_EXPRs could do autoincrements.  */
  6425.   emit_queue ();
  6426. }
  6427.  
  6428. /* Expand a C `return' statement.
  6429.    RETVAL is the expression for what to return,
  6430.    or a null pointer for `return;' with no value.  */
  6431.  
  6432. void
  6433. c_expand_return (retval)
  6434.      tree retval;
  6435. {
  6436.   tree valtype = TREE_TYPE (TREE_TYPE (current_function_decl));
  6437.  
  6438.   if (TREE_THIS_VOLATILE (current_function_decl))
  6439.     warning ("function declared `noreturn' has a `return' statement");
  6440.  
  6441.   if (!retval)
  6442.     {
  6443.       current_function_returns_null = 1;
  6444.       if (warn_return_type && valtype != 0 && TREE_CODE (valtype) != VOID_TYPE)
  6445.     warning ("`return' with no value, in function returning non-void");
  6446.       expand_null_return ();
  6447.     }
  6448.   else if (valtype == 0 || TREE_CODE (valtype) == VOID_TYPE)
  6449.     {
  6450.       current_function_returns_null = 1;
  6451.       if (pedantic || TREE_CODE (TREE_TYPE (retval)) != VOID_TYPE)
  6452.     pedwarn ("`return' with a value, in function returning void");
  6453.       expand_return (retval);
  6454.     }
  6455.   else
  6456.     {
  6457.       tree t = convert_for_assignment (valtype, retval, "return",
  6458.                        NULL_TREE, NULL_TREE, 0);
  6459.       tree res = DECL_RESULT (current_function_decl);
  6460.       tree inner;
  6461.  
  6462.       if (t == error_mark_node)
  6463.     return;
  6464.  
  6465.       inner = t = convert (TREE_TYPE (res), t);
  6466.  
  6467.       /* Strip any conversions, additions, and subtractions, and see if
  6468.      we are returning the address of a local variable.  Warn if so.  */
  6469.       while (1)
  6470.     {
  6471.       switch (TREE_CODE (inner))
  6472.         {
  6473.         case NOP_EXPR:   case NON_LVALUE_EXPR:  case CONVERT_EXPR:
  6474.         case PLUS_EXPR:
  6475.           inner = TREE_OPERAND (inner, 0);
  6476.           continue;
  6477.  
  6478.         case MINUS_EXPR:
  6479.           /* If the second operand of the MINUS_EXPR has a pointer
  6480.          type (or is converted from it), this may be valid, so
  6481.          don't give a warning.  */
  6482.           {
  6483.         tree op1 = TREE_OPERAND (inner, 1);
  6484.  
  6485.         while (! POINTER_TYPE_P (TREE_TYPE (op1))
  6486.                && (TREE_CODE (op1) == NOP_EXPR
  6487.                || TREE_CODE (op1) == NON_LVALUE_EXPR
  6488.                || TREE_CODE (op1) == CONVERT_EXPR))
  6489.           op1 = TREE_OPERAND (op1, 0);
  6490.  
  6491.         if (POINTER_TYPE_P (TREE_TYPE (op1)))
  6492.           break;
  6493.  
  6494.         inner = TREE_OPERAND (inner, 0);
  6495.         continue;
  6496.           }
  6497.           
  6498.         case ADDR_EXPR:
  6499.           inner = TREE_OPERAND (inner, 0);
  6500.  
  6501.           while (TREE_CODE_CLASS (TREE_CODE (inner)) == 'r')
  6502.         inner = TREE_OPERAND (inner, 0);
  6503.  
  6504.           if (TREE_CODE (inner) == VAR_DECL
  6505.           && ! DECL_EXTERNAL (inner)
  6506.           && ! TREE_STATIC (inner)
  6507.           && DECL_CONTEXT (inner) == current_function_decl)
  6508.         warning ("function returns address of local variable");
  6509.           break;
  6510.         }
  6511.  
  6512.       break;
  6513.     }
  6514.  
  6515.       t = build (MODIFY_EXPR, TREE_TYPE (res), res, t);
  6516.       TREE_SIDE_EFFECTS (t) = 1;
  6517.       expand_return (t);
  6518.       current_function_returns_value = 1;
  6519.     }
  6520. }
  6521.  
  6522. /* Start a C switch statement, testing expression EXP.
  6523.    Return EXP if it is valid, an error node otherwise.  */
  6524.  
  6525. tree
  6526. c_expand_start_case (exp)
  6527.      tree exp;
  6528. {
  6529.   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
  6530.   tree type = TREE_TYPE (exp);
  6531.  
  6532.   if (code != INTEGER_TYPE && code != ENUMERAL_TYPE && code != ERROR_MARK)
  6533.     {
  6534.       error ("switch quantity not an integer");
  6535.       exp = error_mark_node;
  6536.     }
  6537.   else
  6538.     {
  6539.       tree index;
  6540.       type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
  6541.  
  6542.       if (warn_traditional
  6543.       && (type == long_integer_type_node
  6544.           || type == long_unsigned_type_node))
  6545.     pedwarn ("`long' switch expression not converted to `int' in ANSI C");
  6546.  
  6547.       exp = default_conversion (exp);
  6548.       type = TREE_TYPE (exp);
  6549.       index = get_unwidened (exp, NULL_TREE);
  6550.       /* We can't strip a conversion from a signed type to an unsigned,
  6551.      because if we did, int_fits_type_p would do the wrong thing
  6552.      when checking case values for being in range,
  6553.      and it's too hard to do the right thing.  */
  6554.       if (TREE_UNSIGNED (TREE_TYPE (exp))
  6555.       == TREE_UNSIGNED (TREE_TYPE (index)))
  6556.     exp = index;
  6557.     }
  6558.  
  6559.   expand_start_case (1, exp, type, "switch statement");
  6560.  
  6561.   return exp;
  6562. }
  6563.